1 //===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASSEMBLER_H
11 #define LLVM_MC_MCASSEMBLER_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/ilist.h"
18 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/ADT/iterator.h"
20 #include "llvm/MC/MCDirectives.h"
21 #include "llvm/MC/MCFixup.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCLinkerOptimizationHint.h"
24 #include "llvm/MC/MCSection.h"
25 #include "llvm/MC/MCSubtargetInfo.h"
26 #include "llvm/MC/MCSymbol.h"
27 #include "llvm/Support/Casting.h"
28 #include "llvm/Support/DataTypes.h"
30 #include <vector> // FIXME: Shouldn't be needed.
42 class MCSubtargetInfo;
46 class MCFragment : public ilist_node<MCFragment> {
47 friend class MCAsmLayout;
49 MCFragment(const MCFragment &) = delete;
50 void operator=(const MCFragment &) = delete;
56 FT_CompactEncodedInst,
69 /// The data for the section this fragment is in.
72 /// Atom - The atom this fragment is in, as represented by it's defining
76 /// \name Assembler Backend Data
79 // FIXME: This could all be kept private to the assembler implementation.
81 /// Offset - The offset of this fragment in its section. This is ~0 until
85 /// LayoutOrder - The layout order of this fragment.
91 MCFragment(FragmentType Kind, MCSection *Parent = nullptr);
96 virtual ~MCFragment();
98 FragmentType getKind() const { return Kind; }
100 MCSection *getParent() const { return Parent; }
101 void setParent(MCSection *Value) { Parent = Value; }
103 const MCSymbol *getAtom() const { return Atom; }
104 void setAtom(const MCSymbol *Value) { Atom = Value; }
106 unsigned getLayoutOrder() const { return LayoutOrder; }
107 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
109 /// \brief Does this fragment have instructions emitted into it? By default
110 /// this is false, but specific fragment types may set it to true.
111 virtual bool hasInstructions() const { return false; }
113 /// \brief Should this fragment be placed at the end of an aligned bundle?
114 virtual bool alignToBundleEnd() const { return false; }
115 virtual void setAlignToBundleEnd(bool V) {}
117 /// \brief Get the padding size that must be inserted before this fragment.
118 /// Used for bundling. By default, no padding is inserted.
119 /// Note that padding size is restricted to 8 bits. This is an optimization
120 /// to reduce the amount of space used for each fragment. In practice, larger
121 /// padding should never be required.
122 virtual uint8_t getBundlePadding() const { return 0; }
124 /// \brief Set the padding size for this fragment. By default it's a no-op,
125 /// and only some fragments have a meaningful implementation.
126 virtual void setBundlePadding(uint8_t N) {}
131 /// Interface implemented by fragments that contain encoded instructions and/or
134 class MCEncodedFragment : public MCFragment {
135 virtual void anchor();
137 uint8_t BundlePadding;
140 MCEncodedFragment(MCFragment::FragmentType FType, MCSection *Sec = nullptr)
141 : MCFragment(FType, Sec), BundlePadding(0) {}
142 ~MCEncodedFragment() override;
144 virtual SmallVectorImpl<char> &getContents() = 0;
145 virtual const SmallVectorImpl<char> &getContents() const = 0;
147 uint8_t getBundlePadding() const override { return BundlePadding; }
149 void setBundlePadding(uint8_t N) override { BundlePadding = N; }
151 static bool classof(const MCFragment *F) {
152 MCFragment::FragmentType Kind = F->getKind();
156 case MCFragment::FT_Relaxable:
157 case MCFragment::FT_CompactEncodedInst:
158 case MCFragment::FT_Data:
164 /// Interface implemented by fragments that contain encoded instructions and/or
165 /// data and also have fixups registered.
167 class MCEncodedFragmentWithFixups : public MCEncodedFragment {
168 void anchor() override;
171 MCEncodedFragmentWithFixups(MCFragment::FragmentType FType,
172 MCSection *Sec = nullptr)
173 : MCEncodedFragment(FType, Sec) {}
175 ~MCEncodedFragmentWithFixups() override;
177 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
178 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
180 virtual SmallVectorImpl<MCFixup> &getFixups() = 0;
181 virtual const SmallVectorImpl<MCFixup> &getFixups() const = 0;
183 virtual fixup_iterator fixup_begin() = 0;
184 virtual const_fixup_iterator fixup_begin() const = 0;
185 virtual fixup_iterator fixup_end() = 0;
186 virtual const_fixup_iterator fixup_end() const = 0;
188 static bool classof(const MCFragment *F) {
189 MCFragment::FragmentType Kind = F->getKind();
190 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data;
194 /// Fragment for data and encoded instructions.
196 class MCDataFragment : public MCEncodedFragmentWithFixups {
197 void anchor() override;
199 /// \brief Does this fragment contain encoded instructions anywhere in it?
200 bool HasInstructions;
202 /// \brief Should this fragment be aligned to the end of a bundle?
203 bool AlignToBundleEnd;
205 SmallVector<char, 32> Contents;
207 /// Fixups - The list of fixups in this fragment.
208 SmallVector<MCFixup, 4> Fixups;
211 MCDataFragment(MCSection *Sec = nullptr)
212 : MCEncodedFragmentWithFixups(FT_Data, Sec), HasInstructions(false),
213 AlignToBundleEnd(false) {}
215 SmallVectorImpl<char> &getContents() override { return Contents; }
216 const SmallVectorImpl<char> &getContents() const override { return Contents; }
218 SmallVectorImpl<MCFixup> &getFixups() override { return Fixups; }
220 const SmallVectorImpl<MCFixup> &getFixups() const override { return Fixups; }
222 bool hasInstructions() const override { return HasInstructions; }
223 virtual void setHasInstructions(bool V) { HasInstructions = V; }
225 bool alignToBundleEnd() const override { return AlignToBundleEnd; }
226 void setAlignToBundleEnd(bool V) override { AlignToBundleEnd = V; }
228 fixup_iterator fixup_begin() override { return Fixups.begin(); }
229 const_fixup_iterator fixup_begin() const override { return Fixups.begin(); }
231 fixup_iterator fixup_end() override { return Fixups.end(); }
232 const_fixup_iterator fixup_end() const override { return Fixups.end(); }
234 static bool classof(const MCFragment *F) {
235 return F->getKind() == MCFragment::FT_Data;
239 /// This is a compact (memory-size-wise) fragment for holding an encoded
240 /// instruction (non-relaxable) that has no fixups registered. When applicable,
241 /// it can be used instead of MCDataFragment and lead to lower memory
244 class MCCompactEncodedInstFragment : public MCEncodedFragment {
245 void anchor() override;
247 /// \brief Should this fragment be aligned to the end of a bundle?
248 bool AlignToBundleEnd;
250 SmallVector<char, 4> Contents;
253 MCCompactEncodedInstFragment(MCSection *Sec = nullptr)
254 : MCEncodedFragment(FT_CompactEncodedInst, Sec), AlignToBundleEnd(false) {
257 bool hasInstructions() const override { return true; }
259 SmallVectorImpl<char> &getContents() override { return Contents; }
260 const SmallVectorImpl<char> &getContents() const override { return Contents; }
262 bool alignToBundleEnd() const override { return AlignToBundleEnd; }
263 void setAlignToBundleEnd(bool V) override { AlignToBundleEnd = V; }
265 static bool classof(const MCFragment *F) {
266 return F->getKind() == MCFragment::FT_CompactEncodedInst;
270 /// A relaxable fragment holds on to its MCInst, since it may need to be
271 /// relaxed during the assembler layout and relaxation stage.
273 class MCRelaxableFragment : public MCEncodedFragmentWithFixups {
274 void anchor() override;
276 /// Inst - The instruction this is a fragment for.
279 /// STI - The MCSubtargetInfo in effect when the instruction was encoded.
280 /// Keep a copy instead of a reference to make sure that updates to STI
281 /// in the assembler are not seen here.
282 const MCSubtargetInfo STI;
284 /// Contents - Binary data for the currently encoded instruction.
285 SmallVector<char, 8> Contents;
287 /// Fixups - The list of fixups in this fragment.
288 SmallVector<MCFixup, 1> Fixups;
291 MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI,
292 MCSection *Sec = nullptr)
293 : MCEncodedFragmentWithFixups(FT_Relaxable, Sec), Inst(Inst), STI(STI) {}
295 SmallVectorImpl<char> &getContents() override { return Contents; }
296 const SmallVectorImpl<char> &getContents() const override { return Contents; }
298 const MCInst &getInst() const { return Inst; }
299 void setInst(const MCInst &Value) { Inst = Value; }
301 const MCSubtargetInfo &getSubtargetInfo() { return STI; }
303 SmallVectorImpl<MCFixup> &getFixups() override { return Fixups; }
305 const SmallVectorImpl<MCFixup> &getFixups() const override { return Fixups; }
307 bool hasInstructions() const override { return true; }
309 fixup_iterator fixup_begin() override { return Fixups.begin(); }
310 const_fixup_iterator fixup_begin() const override { return Fixups.begin(); }
312 fixup_iterator fixup_end() override { return Fixups.end(); }
313 const_fixup_iterator fixup_end() const override { return Fixups.end(); }
315 static bool classof(const MCFragment *F) {
316 return F->getKind() == MCFragment::FT_Relaxable;
320 class MCAlignFragment : public MCFragment {
321 virtual void anchor();
323 /// Alignment - The alignment to ensure, in bytes.
326 /// Value - Value to use for filling padding bytes.
329 /// ValueSize - The size of the integer (in bytes) of \p Value.
332 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
333 /// cannot be satisfied in this width then this fragment is ignored.
334 unsigned MaxBytesToEmit;
336 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
337 /// of using the provided value. The exact interpretation of this flag is
338 /// target dependent.
342 MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
343 unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
344 : MCFragment(FT_Align, Sec), Alignment(Alignment), Value(Value),
345 ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit), EmitNops(false) {}
350 unsigned getAlignment() const { return Alignment; }
352 int64_t getValue() const { return Value; }
354 unsigned getValueSize() const { return ValueSize; }
356 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
358 bool hasEmitNops() const { return EmitNops; }
359 void setEmitNops(bool Value) { EmitNops = Value; }
363 static bool classof(const MCFragment *F) {
364 return F->getKind() == MCFragment::FT_Align;
368 class MCFillFragment : public MCFragment {
369 virtual void anchor();
371 /// Value - Value to use for filling bytes.
374 /// ValueSize - The size (in bytes) of \p Value to use when filling, or 0 if
375 /// this is a virtual fill fragment.
378 /// Size - The number of bytes to insert.
382 MCFillFragment(int64_t Value, unsigned ValueSize, uint64_t Size,
383 MCSection *Sec = nullptr)
384 : MCFragment(FT_Fill, Sec), Value(Value), ValueSize(ValueSize),
386 assert((!ValueSize || (Size % ValueSize) == 0) &&
387 "Fill size must be a multiple of the value size!");
393 int64_t getValue() const { return Value; }
395 unsigned getValueSize() const { return ValueSize; }
397 uint64_t getSize() const { return Size; }
401 static bool classof(const MCFragment *F) {
402 return F->getKind() == MCFragment::FT_Fill;
406 class MCOrgFragment : public MCFragment {
407 virtual void anchor();
409 /// Offset - The offset this fragment should start at.
410 const MCExpr *Offset;
412 /// Value - Value to use for filling bytes.
416 MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSection *Sec = nullptr)
417 : MCFragment(FT_Org, Sec), Offset(&Offset), Value(Value) {}
422 const MCExpr &getOffset() const { return *Offset; }
424 uint8_t getValue() const { return Value; }
428 static bool classof(const MCFragment *F) {
429 return F->getKind() == MCFragment::FT_Org;
433 class MCLEBFragment : public MCFragment {
434 virtual void anchor();
436 /// Value - The value this fragment should contain.
439 /// IsSigned - True if this is a sleb128, false if uleb128.
442 SmallString<8> Contents;
445 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
446 : MCFragment(FT_LEB, Sec), Value(&Value_), IsSigned(IsSigned_) {
447 Contents.push_back(0);
453 const MCExpr &getValue() const { return *Value; }
455 bool isSigned() const { return IsSigned; }
457 SmallString<8> &getContents() { return Contents; }
458 const SmallString<8> &getContents() const { return Contents; }
462 static bool classof(const MCFragment *F) {
463 return F->getKind() == MCFragment::FT_LEB;
467 class MCDwarfLineAddrFragment : public MCFragment {
468 virtual void anchor();
470 /// LineDelta - the value of the difference between the two line numbers
471 /// between two .loc dwarf directives.
474 /// AddrDelta - The expression for the difference of the two symbols that
475 /// make up the address delta between two .loc dwarf directives.
476 const MCExpr *AddrDelta;
478 SmallString<8> Contents;
481 MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta,
482 MCSection *Sec = nullptr)
483 : MCFragment(FT_Dwarf, Sec), LineDelta(LineDelta), AddrDelta(&AddrDelta) {
484 Contents.push_back(0);
490 int64_t getLineDelta() const { return LineDelta; }
492 const MCExpr &getAddrDelta() const { return *AddrDelta; }
494 SmallString<8> &getContents() { return Contents; }
495 const SmallString<8> &getContents() const { return Contents; }
499 static bool classof(const MCFragment *F) {
500 return F->getKind() == MCFragment::FT_Dwarf;
504 class MCDwarfCallFrameFragment : public MCFragment {
505 virtual void anchor();
507 /// AddrDelta - The expression for the difference of the two symbols that
508 /// make up the address delta between two .cfi_* dwarf directives.
509 const MCExpr *AddrDelta;
511 SmallString<8> Contents;
514 MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
515 : MCFragment(FT_DwarfFrame, Sec), AddrDelta(&AddrDelta) {
516 Contents.push_back(0);
522 const MCExpr &getAddrDelta() const { return *AddrDelta; }
524 SmallString<8> &getContents() { return Contents; }
525 const SmallString<8> &getContents() const { return Contents; }
529 static bool classof(const MCFragment *F) {
530 return F->getKind() == MCFragment::FT_DwarfFrame;
534 class MCSafeSEHFragment : public MCFragment {
535 virtual void anchor();
540 MCSafeSEHFragment(const MCSymbol *Sym, MCSection *Sec = nullptr)
541 : MCFragment(FT_SafeSEH, Sec), Sym(Sym) {}
546 const MCSymbol *getSymbol() { return Sym; }
547 const MCSymbol *getSymbol() const { return Sym; }
551 static bool classof(const MCFragment *F) {
552 return F->getKind() == MCFragment::FT_SafeSEH;
556 // FIXME: This really doesn't belong here. See comments below.
557 struct IndirectSymbolData {
562 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
564 struct DataRegionData {
565 // This enum should be kept in sync w/ the mach-o definition in
566 // llvm/Object/MachOFormat.h.
567 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
573 friend class MCAsmLayout;
576 typedef std::vector<MCSection *> SectionListType;
577 typedef std::vector<const MCSymbol *> SymbolDataListType;
579 typedef pointee_iterator<SectionListType::const_iterator> const_iterator;
580 typedef pointee_iterator<SectionListType::iterator> iterator;
582 typedef pointee_iterator<SymbolDataListType::const_iterator>
583 const_symbol_iterator;
584 typedef pointee_iterator<SymbolDataListType::iterator> symbol_iterator;
586 typedef iterator_range<symbol_iterator> symbol_range;
587 typedef iterator_range<const_symbol_iterator> const_symbol_range;
589 typedef std::vector<IndirectSymbolData>::const_iterator
590 const_indirect_symbol_iterator;
591 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
593 typedef std::vector<DataRegionData>::const_iterator
594 const_data_region_iterator;
595 typedef std::vector<DataRegionData>::iterator data_region_iterator;
597 /// MachO specific deployment target version info.
598 // A Major version of 0 indicates that no version information was supplied
599 // and so the corresponding load command should not be emitted.
601 MCVersionMinType Kind;
605 } VersionMinInfoType;
608 MCAssembler(const MCAssembler &) = delete;
609 void operator=(const MCAssembler &) = delete;
613 MCAsmBackend &Backend;
615 MCCodeEmitter &Emitter;
617 MCObjectWriter &Writer;
621 SectionListType Sections;
623 SymbolDataListType Symbols;
625 DenseSet<const MCSymbol *> LocalsUsedInReloc;
627 std::vector<IndirectSymbolData> IndirectSymbols;
629 std::vector<DataRegionData> DataRegions;
631 /// The list of linker options to propagate into the object file.
632 std::vector<std::vector<std::string>> LinkerOptions;
634 /// List of declared file names
635 std::vector<std::string> FileNames;
637 /// The set of function symbols for which a .thumb_func directive has
640 // FIXME: We really would like this in target specific code rather than
641 // here. Maybe when the relocation stuff moves to target specific,
642 // this can go with it? The streamer would need some target specific
644 mutable SmallPtrSet<const MCSymbol *, 64> ThumbFuncs;
646 /// \brief The bundle alignment size currently set in the assembler.
648 /// By default it's 0, which means bundling is disabled.
649 unsigned BundleAlignSize;
651 unsigned RelaxAll : 1;
652 unsigned SubsectionsViaSymbols : 1;
654 /// ELF specific e_header flags
655 // It would be good if there were an MCELFAssembler class to hold this.
656 // ELF header flags are used both by the integrated and standalone assemblers.
657 // Access to the flags is necessary in cases where assembler directives affect
658 // which flags to be set.
659 unsigned ELFHeaderEFlags;
661 /// Used to communicate Linker Optimization Hint information between
662 /// the Streamer and the .o writer
663 MCLOHContainer LOHContainer;
665 VersionMinInfoType VersionMinInfo;
668 /// Evaluate a fixup to a relocatable expression and the value which should be
669 /// placed into the fixup.
671 /// \param Layout The layout to use for evaluation.
672 /// \param Fixup The fixup to evaluate.
673 /// \param DF The fragment the fixup is inside.
674 /// \param Target [out] On return, the relocatable expression the fixup
676 /// \param Value [out] On return, the value of the fixup as currently laid
678 /// \return Whether the fixup value was fully resolved. This is true if the
679 /// \p Value result is fixed, otherwise the value may change due to
681 bool evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup,
682 const MCFragment *DF, MCValue &Target,
683 uint64_t &Value) const;
685 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
686 /// (increased in size, in order to hold its value correctly).
687 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCRelaxableFragment *DF,
688 const MCAsmLayout &Layout) const;
690 /// Check whether the given fragment needs relaxation.
691 bool fragmentNeedsRelaxation(const MCRelaxableFragment *IF,
692 const MCAsmLayout &Layout) const;
694 /// \brief Perform one layout iteration and return true if any offsets
696 bool layoutOnce(MCAsmLayout &Layout);
698 /// \brief Perform one layout iteration of the given section and return true
699 /// if any offsets were adjusted.
700 bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec);
702 bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
704 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
706 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
707 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
708 MCDwarfCallFrameFragment &DF);
710 /// finishLayout - Finalize a layout, including fragment lowering.
711 void finishLayout(MCAsmLayout &Layout);
713 std::pair<uint64_t, bool> handleFixup(const MCAsmLayout &Layout,
714 MCFragment &F, const MCFixup &Fixup);
717 void addLocalUsedInReloc(const MCSymbol &Sym);
718 bool isLocalUsedInReloc(const MCSymbol &Sym) const;
720 /// Compute the effective fragment size assuming it is laid out at the given
721 /// \p SectionAddress and \p FragmentOffset.
722 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
723 const MCFragment &F) const;
725 /// Find the symbol which defines the atom containing the given symbol, or
726 /// null if there is no such symbol.
727 const MCSymbol *getAtom(const MCSymbol &S) const;
729 /// Check whether a particular symbol is visible to the linker and is required
730 /// in the symbol table, or whether it can be discarded by the assembler. This
731 /// also effects whether the assembler treats the label as potentially
732 /// defining a separate atom.
733 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
735 /// Emit the section contents using the given object writer.
736 void writeSectionData(const MCSection *Section,
737 const MCAsmLayout &Layout) const;
739 /// Check whether a given symbol has been flagged with .thumb_func.
740 bool isThumbFunc(const MCSymbol *Func) const;
742 /// Flag a function symbol as the target of a .thumb_func directive.
743 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
745 /// ELF e_header flags
746 unsigned getELFHeaderEFlags() const { return ELFHeaderEFlags; }
747 void setELFHeaderEFlags(unsigned Flags) { ELFHeaderEFlags = Flags; }
749 /// MachO deployment target version information.
750 const VersionMinInfoType &getVersionMinInfo() const { return VersionMinInfo; }
751 void setVersionMinInfo(MCVersionMinType Kind, unsigned Major, unsigned Minor,
753 VersionMinInfo.Kind = Kind;
754 VersionMinInfo.Major = Major;
755 VersionMinInfo.Minor = Minor;
756 VersionMinInfo.Update = Update;
760 /// Construct a new assembler instance.
762 /// \param OS The stream to output to.
764 // FIXME: How are we going to parameterize this? Two obvious options are stay
765 // concrete and require clients to pass in a target like object. The other
766 // option is to make this abstract, and have targets provide concrete
767 // implementations as we do with AsmParser.
768 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
769 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
773 /// Reuse an assembler instance
777 MCContext &getContext() const { return Context; }
779 MCAsmBackend &getBackend() const { return Backend; }
781 MCCodeEmitter &getEmitter() const { return Emitter; }
783 MCObjectWriter &getWriter() const { return Writer; }
785 /// Finish - Do final processing and write the object to the output stream.
786 /// \p Writer is used for custom object writer (as the MCJIT does),
787 /// if not specified it is automatically created from backend.
790 // FIXME: This does not belong here.
791 bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
792 void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
794 bool getRelaxAll() const { return RelaxAll; }
795 void setRelaxAll(bool Value) { RelaxAll = Value; }
797 bool isBundlingEnabled() const { return BundleAlignSize != 0; }
799 unsigned getBundleAlignSize() const { return BundleAlignSize; }
801 void setBundleAlignSize(unsigned Size) {
802 assert((Size == 0 || !(Size & (Size - 1))) &&
803 "Expect a power-of-two bundle align size");
804 BundleAlignSize = Size;
807 /// \name Section List Access
810 iterator begin() { return Sections.begin(); }
811 const_iterator begin() const { return Sections.begin(); }
813 iterator end() { return Sections.end(); }
814 const_iterator end() const { return Sections.end(); }
816 size_t size() const { return Sections.size(); }
819 /// \name Symbol List Access
821 symbol_iterator symbol_begin() { return Symbols.begin(); }
822 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
824 symbol_iterator symbol_end() { return Symbols.end(); }
825 const_symbol_iterator symbol_end() const { return Symbols.end(); }
827 symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
828 const_symbol_range symbols() const {
829 return make_range(symbol_begin(), symbol_end());
832 size_t symbol_size() const { return Symbols.size(); }
835 /// \name Indirect Symbol List Access
838 // FIXME: This is a total hack, this should not be here. Once things are
839 // factored so that the streamer has direct access to the .o writer, it can
841 std::vector<IndirectSymbolData> &getIndirectSymbols() {
842 return IndirectSymbols;
845 indirect_symbol_iterator indirect_symbol_begin() {
846 return IndirectSymbols.begin();
848 const_indirect_symbol_iterator indirect_symbol_begin() const {
849 return IndirectSymbols.begin();
852 indirect_symbol_iterator indirect_symbol_end() {
853 return IndirectSymbols.end();
855 const_indirect_symbol_iterator indirect_symbol_end() const {
856 return IndirectSymbols.end();
859 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
862 /// \name Linker Option List Access
865 std::vector<std::vector<std::string>> &getLinkerOptions() {
866 return LinkerOptions;
870 /// \name Data Region List Access
873 // FIXME: This is a total hack, this should not be here. Once things are
874 // factored so that the streamer has direct access to the .o writer, it can
876 std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
878 data_region_iterator data_region_begin() { return DataRegions.begin(); }
879 const_data_region_iterator data_region_begin() const {
880 return DataRegions.begin();
883 data_region_iterator data_region_end() { return DataRegions.end(); }
884 const_data_region_iterator data_region_end() const {
885 return DataRegions.end();
888 size_t data_region_size() const { return DataRegions.size(); }
891 /// \name Data Region List Access
894 // FIXME: This is a total hack, this should not be here. Once things are
895 // factored so that the streamer has direct access to the .o writer, it can
897 MCLOHContainer &getLOHContainer() { return LOHContainer; }
898 const MCLOHContainer &getLOHContainer() const {
899 return const_cast<MCAssembler *>(this)->getLOHContainer();
902 /// \name Backend Data Access
905 bool registerSection(MCSection &Section) {
906 if (Section.isRegistered())
908 Sections.push_back(&Section);
909 Section.setIsRegistered(true);
913 void registerSymbol(const MCSymbol &Symbol, bool *Created = nullptr) {
914 bool New = !Symbol.isRegistered();
918 Symbol.setIsRegistered(true);
919 Symbols.push_back(&Symbol);
923 ArrayRef<std::string> getFileNames() { return FileNames; }
925 void addFileName(StringRef FileName) {
926 if (std::find(FileNames.begin(), FileNames.end(), FileName) ==
928 FileNames.push_back(FileName);
931 /// \brief Write the necessary bundle padding to the given object writer.
932 /// Expects a fragment \p F containing instructions and its size \p FSize.
933 void writeFragmentPadding(const MCFragment &F, uint64_t FSize,
934 MCObjectWriter *OW) const;
941 /// \brief Compute the amount of padding required before the fragment \p F to
942 /// obey bundling restrictions, where \p FOffset is the fragment's offset in
943 /// its section and \p FSize is the fragment's size.
944 uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F,
945 uint64_t FOffset, uint64_t FSize);
947 } // end namespace llvm