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/SmallString.h"
15 #include "llvm/ADT/ilist.h"
16 #include "llvm/ADT/ilist_node.h"
17 #include "llvm/Support/Casting.h"
18 #include "llvm/MC/MCFixup.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/System/DataTypes.h"
21 #include <vector> // FIXME: Shouldn't be needed.
38 class TargetAsmBackend;
40 class MCFragment : public ilist_node<MCFragment> {
41 friend class MCAsmLayout;
43 MCFragment(const MCFragment&); // DO NOT IMPLEMENT
44 void operator=(const MCFragment&); // DO NOT IMPLEMENT
60 /// Parent - The data for the section this fragment is in.
61 MCSectionData *Parent;
63 /// Atom - The atom this fragment is in, as represented by it's defining
64 /// symbol. Atom's are only used by backends which set
65 /// \see MCAsmBackend::hasReliableSymbolDifference().
68 /// @name Assembler Backend Data
71 // FIXME: This could all be kept private to the assembler implementation.
73 /// Offset - The offset of this fragment in its section. This is ~0 until
77 /// EffectiveSize - The compute size of this section. This is ~0 until
79 uint64_t EffectiveSize;
81 /// LayoutOrder - The global layout order of this fragment. This is the index
82 /// across all fragments in the file, not just within the section.
88 MCFragment(FragmentType _Kind, MCSectionData *_Parent = 0);
93 virtual ~MCFragment();
95 FragmentType getKind() const { return Kind; }
97 MCSectionData *getParent() const { return Parent; }
98 void setParent(MCSectionData *Value) { Parent = Value; }
100 MCSymbolData *getAtom() const { return Atom; }
101 void setAtom(MCSymbolData *Value) { Atom = Value; }
103 unsigned getLayoutOrder() const { return LayoutOrder; }
104 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
106 static bool classof(const MCFragment *O) { return true; }
111 class MCDataFragment : public MCFragment {
112 SmallString<32> Contents;
114 /// Fixups - The list of fixups in this fragment.
115 std::vector<MCFixup> Fixups;
118 typedef std::vector<MCFixup>::const_iterator const_fixup_iterator;
119 typedef std::vector<MCFixup>::iterator fixup_iterator;
122 MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
127 SmallString<32> &getContents() { return Contents; }
128 const SmallString<32> &getContents() const { return Contents; }
131 /// @name Fixup Access
134 void addFixup(MCFixup Fixup) {
135 // Enforce invariant that fixups are in offset order.
136 assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
137 "Fixups must be added in order!");
138 Fixups.push_back(Fixup);
141 std::vector<MCFixup> &getFixups() { return Fixups; }
142 const std::vector<MCFixup> &getFixups() const { return Fixups; }
144 fixup_iterator fixup_begin() { return Fixups.begin(); }
145 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
147 fixup_iterator fixup_end() {return Fixups.end();}
148 const_fixup_iterator fixup_end() const {return Fixups.end();}
150 size_t fixup_size() const { return Fixups.size(); }
154 static bool classof(const MCFragment *F) {
155 return F->getKind() == MCFragment::FT_Data;
157 static bool classof(const MCDataFragment *) { return true; }
160 // FIXME: This current incarnation of MCInstFragment doesn't make much sense, as
161 // it is almost entirely a duplicate of MCDataFragment. If we decide to stick
162 // with this approach (as opposed to making MCInstFragment a very light weight
163 // object with just the MCInst and a code size, then we should just change
164 // MCDataFragment to have an optional MCInst at its end.
165 class MCInstFragment : public MCFragment {
166 /// Inst - The instruction this is a fragment for.
169 /// Code - Binary data for the currently encoded instruction.
172 /// Fixups - The list of fixups in this fragment.
173 SmallVector<MCFixup, 1> Fixups;
176 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
177 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
180 MCInstFragment(MCInst _Inst, MCSectionData *SD = 0)
181 : MCFragment(FT_Inst, SD), Inst(_Inst) {
187 SmallVectorImpl<char> &getCode() { return Code; }
188 const SmallVectorImpl<char> &getCode() const { return Code; }
190 unsigned getInstSize() const { return Code.size(); }
192 MCInst &getInst() { return Inst; }
193 const MCInst &getInst() const { return Inst; }
195 void setInst(MCInst Value) { Inst = Value; }
198 /// @name Fixup Access
201 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
202 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
204 fixup_iterator fixup_begin() { return Fixups.begin(); }
205 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
207 fixup_iterator fixup_end() {return Fixups.end();}
208 const_fixup_iterator fixup_end() const {return Fixups.end();}
210 size_t fixup_size() const { return Fixups.size(); }
214 static bool classof(const MCFragment *F) {
215 return F->getKind() == MCFragment::FT_Inst;
217 static bool classof(const MCInstFragment *) { return true; }
220 class MCAlignFragment : public MCFragment {
221 /// Alignment - The alignment to ensure, in bytes.
224 /// Value - Value to use for filling padding bytes.
227 /// ValueSize - The size of the integer (in bytes) of \arg Value.
230 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
231 /// cannot be satisfied in this width then this fragment is ignored.
232 unsigned MaxBytesToEmit;
234 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
235 /// of using the provided value. The exact interpretation of this flag is
236 /// target dependent.
239 /// OnlyAlignAddress - Flag to indicate that this align is only used to adjust
240 /// the address space size of a section and that it should not be included as
241 /// part of the section size. This flag can only be used on the last fragment
243 bool OnlyAlignAddress : 1;
246 MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize,
247 unsigned _MaxBytesToEmit, MCSectionData *SD = 0)
248 : MCFragment(FT_Align, SD), Alignment(_Alignment),
249 Value(_Value),ValueSize(_ValueSize),
250 MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false),
251 OnlyAlignAddress(false) {}
256 unsigned getAlignment() const { return Alignment; }
258 int64_t getValue() const { return Value; }
260 unsigned getValueSize() const { return ValueSize; }
262 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
264 bool hasEmitNops() const { return EmitNops; }
265 void setEmitNops(bool Value) { EmitNops = Value; }
267 bool hasOnlyAlignAddress() const { return OnlyAlignAddress; }
268 void setOnlyAlignAddress(bool Value) { OnlyAlignAddress = Value; }
272 static bool classof(const MCFragment *F) {
273 return F->getKind() == MCFragment::FT_Align;
275 static bool classof(const MCAlignFragment *) { return true; }
278 class MCFillFragment : public MCFragment {
279 /// Value - Value to use for filling bytes.
282 /// ValueSize - The size (in bytes) of \arg Value to use when filling, or 0 if
283 /// this is a virtual fill fragment.
286 /// Size - The number of bytes to insert.
290 MCFillFragment(int64_t _Value, unsigned _ValueSize, uint64_t _Size,
291 MCSectionData *SD = 0)
292 : MCFragment(FT_Fill, SD),
293 Value(_Value), ValueSize(_ValueSize), Size(_Size) {
294 assert((!ValueSize || (Size % ValueSize) == 0) &&
295 "Fill size must be a multiple of the value size!");
301 int64_t getValue() const { return Value; }
303 unsigned getValueSize() const { return ValueSize; }
305 uint64_t getSize() const { return Size; }
309 static bool classof(const MCFragment *F) {
310 return F->getKind() == MCFragment::FT_Fill;
312 static bool classof(const MCFillFragment *) { return true; }
315 class MCOrgFragment : public MCFragment {
316 /// Offset - The offset this fragment should start at.
317 const MCExpr *Offset;
319 /// Value - Value to use for filling bytes.
322 /// Size - The current estimate of the size.
326 MCOrgFragment(const MCExpr &_Offset, int8_t _Value, MCSectionData *SD = 0)
327 : MCFragment(FT_Org, SD),
328 Offset(&_Offset), Value(_Value), Size(0) {}
333 const MCExpr &getOffset() const { return *Offset; }
335 uint8_t getValue() const { return Value; }
337 unsigned getSize() const { return Size; }
339 void setSize(unsigned Size_) { Size = Size_; }
342 static bool classof(const MCFragment *F) {
343 return F->getKind() == MCFragment::FT_Org;
345 static bool classof(const MCOrgFragment *) { return true; }
348 class MCLEBFragment : public MCFragment {
349 /// Value - The value this fragment should contain.
352 /// IsSigned - True if this is a sleb128, false if uleb128.
355 /// Size - The current size estimate.
359 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSectionData *SD)
360 : MCFragment(FT_LEB, SD),
361 Value(&Value_), IsSigned(IsSigned_), Size(1) {}
366 const MCExpr &getValue() const { return *Value; }
368 bool isSigned() const { return IsSigned; }
370 uint64_t getSize() const { return Size; }
372 void setSize(uint64_t Size_) { Size = Size_; }
376 static bool classof(const MCFragment *F) {
377 return F->getKind() == MCFragment::FT_LEB;
379 static bool classof(const MCLEBFragment *) { return true; }
382 class MCDwarfLineAddrFragment : public MCFragment {
383 /// LineDelta - the value of the difference between the two line numbers
384 /// between two .loc dwarf directives.
387 /// AddrDelta - The expression for the difference of the two symbols that
388 /// make up the address delta between two .loc dwarf directives.
389 const MCExpr *AddrDelta;
392 MCDwarfLineAddrFragment(int64_t _LineDelta, const MCExpr &_AddrDelta,
393 MCSectionData *SD = 0)
394 : MCFragment(FT_Dwarf, SD),
395 LineDelta(_LineDelta), AddrDelta(&_AddrDelta) {}
400 int64_t getLineDelta() const { return LineDelta; }
402 const MCExpr &getAddrDelta() const { return *AddrDelta; }
406 static bool classof(const MCFragment *F) {
407 return F->getKind() == MCFragment::FT_Dwarf;
409 static bool classof(const MCDwarfLineAddrFragment *) { return true; }
412 // FIXME: Should this be a separate class, or just merged into MCSection? Since
413 // we anticipate the fast path being through an MCAssembler, the only reason to
414 // keep it out is for API abstraction.
415 class MCSectionData : public ilist_node<MCSectionData> {
416 friend class MCAsmLayout;
418 MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT
419 void operator=(const MCSectionData&); // DO NOT IMPLEMENT
422 typedef iplist<MCFragment> FragmentListType;
424 typedef FragmentListType::const_iterator const_iterator;
425 typedef FragmentListType::iterator iterator;
427 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
428 typedef FragmentListType::reverse_iterator reverse_iterator;
431 FragmentListType Fragments;
432 const MCSection *Section;
434 /// Ordinal - The section index in the assemblers section list.
437 /// LayoutOrder - The index of this section in the layout order.
438 unsigned LayoutOrder;
440 /// Alignment - The maximum alignment seen in this section.
443 /// @name Assembler Backend Data
446 // FIXME: This could all be kept private to the assembler implementation.
448 /// Address - The computed address of this section. This is ~0 until
452 /// HasInstructions - Whether this section has had instructions emitted into
454 unsigned HasInstructions : 1;
459 // Only for use as sentinel.
461 MCSectionData(const MCSection &Section, MCAssembler *A = 0);
463 const MCSection &getSection() const { return *Section; }
465 unsigned getAlignment() const { return Alignment; }
466 void setAlignment(unsigned Value) { Alignment = Value; }
468 bool hasInstructions() const { return HasInstructions; }
469 void setHasInstructions(bool Value) { HasInstructions = Value; }
471 unsigned getOrdinal() const { return Ordinal; }
472 void setOrdinal(unsigned Value) { Ordinal = Value; }
474 unsigned getLayoutOrder() const { return LayoutOrder; }
475 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
477 /// @name Fragment Access
480 const FragmentListType &getFragmentList() const { return Fragments; }
481 FragmentListType &getFragmentList() { return Fragments; }
483 iterator begin() { return Fragments.begin(); }
484 const_iterator begin() const { return Fragments.begin(); }
486 iterator end() { return Fragments.end(); }
487 const_iterator end() const { return Fragments.end(); }
489 reverse_iterator rbegin() { return Fragments.rbegin(); }
490 const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
492 reverse_iterator rend() { return Fragments.rend(); }
493 const_reverse_iterator rend() const { return Fragments.rend(); }
495 size_t size() const { return Fragments.size(); }
497 bool empty() const { return Fragments.empty(); }
504 // FIXME: Same concerns as with SectionData.
505 class MCSymbolData : public ilist_node<MCSymbolData> {
507 const MCSymbol *Symbol;
509 /// Fragment - The fragment this symbol's value is relative to, if any.
510 MCFragment *Fragment;
512 /// Offset - The offset to apply to the fragment address to form this symbol's
516 /// IsExternal - True if this symbol is visible outside this translation
518 unsigned IsExternal : 1;
520 /// IsPrivateExtern - True if this symbol is private extern.
521 unsigned IsPrivateExtern : 1;
523 /// CommonSize - The size of the symbol, if it is 'common', or 0.
525 // FIXME: Pack this in with other fields? We could put it in offset, since a
526 // common symbol can never get a definition.
529 /// SymbolSize - An expression describing how to calculate the size of
530 /// a symbol. If a symbol has no size this field will be NULL.
531 const MCExpr *SymbolSize;
533 /// CommonAlign - The alignment of the symbol, if it is 'common'.
535 // FIXME: Pack this in with other fields?
536 unsigned CommonAlign;
538 /// Flags - The Flags field is used by object file implementations to store
539 /// additional per symbol information which is not easily classified.
542 /// Index - Index field, for use by the object file implementation.
546 // Only for use as sentinel.
548 MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment, uint64_t _Offset,
554 const MCSymbol &getSymbol() const { return *Symbol; }
556 MCFragment *getFragment() const { return Fragment; }
557 void setFragment(MCFragment *Value) { Fragment = Value; }
559 uint64_t getOffset() const { return Offset; }
560 void setOffset(uint64_t Value) { Offset = Value; }
563 /// @name Symbol Attributes
566 bool isExternal() const { return IsExternal; }
567 void setExternal(bool Value) { IsExternal = Value; }
569 bool isPrivateExtern() const { return IsPrivateExtern; }
570 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
572 /// isCommon - Is this a 'common' symbol.
573 bool isCommon() const { return CommonSize != 0; }
575 /// setCommon - Mark this symbol as being 'common'.
577 /// \param Size - The size of the symbol.
578 /// \param Align - The alignment of the symbol.
579 void setCommon(uint64_t Size, unsigned Align) {
584 /// getCommonSize - Return the size of a 'common' symbol.
585 uint64_t getCommonSize() const {
586 assert(isCommon() && "Not a 'common' symbol!");
590 void setSize(const MCExpr *SS) {
594 const MCExpr *getSize() const {
599 /// getCommonAlignment - Return the alignment of a 'common' symbol.
600 unsigned getCommonAlignment() const {
601 assert(isCommon() && "Not a 'common' symbol!");
605 /// getFlags - Get the (implementation defined) symbol flags.
606 uint32_t getFlags() const { return Flags; }
608 /// setFlags - Set the (implementation defined) symbol flags.
609 void setFlags(uint32_t Value) { Flags = Value; }
611 /// modifyFlags - Modify the flags via a mask
612 void modifyFlags(uint32_t Value, uint32_t Mask) {
613 Flags = (Flags & ~Mask) | Value;
616 /// getIndex - Get the (implementation defined) index.
617 uint64_t getIndex() const { return Index; }
619 /// setIndex - Set the (implementation defined) index.
620 void setIndex(uint64_t Value) { Index = Value; }
627 // FIXME: This really doesn't belong here. See comments below.
628 struct IndirectSymbolData {
630 MCSectionData *SectionData;
634 friend class MCAsmLayout;
637 typedef iplist<MCSectionData> SectionDataListType;
638 typedef iplist<MCSymbolData> SymbolDataListType;
640 typedef SectionDataListType::const_iterator const_iterator;
641 typedef SectionDataListType::iterator iterator;
643 typedef SymbolDataListType::const_iterator const_symbol_iterator;
644 typedef SymbolDataListType::iterator symbol_iterator;
646 typedef std::vector<IndirectSymbolData>::const_iterator
647 const_indirect_symbol_iterator;
648 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
651 MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT
652 void operator=(const MCAssembler&); // DO NOT IMPLEMENT
656 TargetAsmBackend &Backend;
658 MCCodeEmitter &Emitter;
662 iplist<MCSectionData> Sections;
664 iplist<MCSymbolData> Symbols;
666 /// The map of sections to their associated assembler backend data.
668 // FIXME: Avoid this indirection?
669 DenseMap<const MCSection*, MCSectionData*> SectionMap;
671 /// The map of symbols to their associated assembler backend data.
673 // FIXME: Avoid this indirection?
674 DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap;
676 std::vector<IndirectSymbolData> IndirectSymbols;
678 unsigned RelaxAll : 1;
679 unsigned SubsectionsViaSymbols : 1;
680 unsigned PadSectionToAlignment : 1;
683 /// Evaluate a fixup to a relocatable expression and the value which should be
684 /// placed into the fixup.
686 /// \param Layout The layout to use for evaluation.
687 /// \param Fixup The fixup to evaluate.
688 /// \param DF The fragment the fixup is inside.
689 /// \param Target [out] On return, the relocatable expression the fixup
691 /// \param Value [out] On return, the value of the fixup as currently layed
693 /// \return Whether the fixup value was fully resolved. This is true if the
694 /// \arg Value result is fixed, otherwise the value may change due to
696 bool EvaluateFixup(const MCObjectWriter &Writer, const MCAsmLayout &Layout,
697 const MCFixup &Fixup, const MCFragment *DF,
698 MCValue &Target, uint64_t &Value) const;
700 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
701 /// (increased in size, in order to hold its value correctly).
702 bool FixupNeedsRelaxation(const MCObjectWriter &Writer,
703 const MCFixup &Fixup, const MCFragment *DF,
704 const MCAsmLayout &Layout) const;
706 /// Check whether the given fragment needs relaxation.
707 bool FragmentNeedsRelaxation(const MCObjectWriter &Writer,
708 const MCInstFragment *IF,
709 const MCAsmLayout &Layout) const;
711 /// Compute the effective fragment size assuming it is layed out at the given
712 /// \arg SectionAddress and \arg FragmentOffset.
713 uint64_t ComputeFragmentSize(MCAsmLayout &Layout, const MCFragment &F,
714 uint64_t SectionAddress,
715 uint64_t FragmentOffset) const;
717 /// LayoutOnce - Perform one layout iteration and return true if any offsets
719 bool LayoutOnce(const MCObjectWriter &Writer, MCAsmLayout &Layout);
721 bool RelaxInstruction(const MCObjectWriter &Writer, MCAsmLayout &Layout,
724 bool RelaxOrg(const MCObjectWriter &Writer, MCAsmLayout &Layout,
727 bool RelaxLEB(const MCObjectWriter &Writer, MCAsmLayout &Layout,
730 /// FinishLayout - Finalize a layout, including fragment lowering.
731 void FinishLayout(MCAsmLayout &Layout);
734 /// Find the symbol which defines the atom containing the given symbol, or
735 /// null if there is no such symbol.
736 const MCSymbolData *getAtom(const MCSymbolData *Symbol) const;
738 /// Check whether a particular symbol is visible to the linker and is required
739 /// in the symbol table, or whether it can be discarded by the assembler. This
740 /// also effects whether the assembler treats the label as potentially
741 /// defining a separate atom.
742 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
744 /// Emit the section contents using the given object writer.
746 // FIXME: Should MCAssembler always have a reference to the object writer?
747 void WriteSectionData(const MCSectionData *Section, const MCAsmLayout &Layout,
748 MCObjectWriter *OW) const;
750 void AddSectionToTheEnd(const MCObjectWriter &Writer, MCSectionData &SD,
751 MCAsmLayout &Layout);
754 /// Construct a new assembler instance.
756 /// \arg OS - The stream to output to.
758 // FIXME: How are we going to parameterize this? Two obvious options are stay
759 // concrete and require clients to pass in a target like object. The other
760 // option is to make this abstract, and have targets provide concrete
761 // implementations as we do with AsmParser.
762 MCAssembler(MCContext &_Context, TargetAsmBackend &_Backend,
763 MCCodeEmitter &_Emitter, bool _PadSectionToAlignment,
767 MCContext &getContext() const { return Context; }
769 TargetAsmBackend &getBackend() const { return Backend; }
771 MCCodeEmitter &getEmitter() const { return Emitter; }
773 /// Finish - Do final processing and write the object to the output stream.
774 /// \arg Writer is used for custom object writer (as the MCJIT does),
775 /// if not specified it is automatically created from backend.
776 void Finish(MCObjectWriter *Writer = 0);
778 // FIXME: This does not belong here.
779 bool getSubsectionsViaSymbols() const {
780 return SubsectionsViaSymbols;
782 void setSubsectionsViaSymbols(bool Value) {
783 SubsectionsViaSymbols = Value;
786 bool getRelaxAll() const { return RelaxAll; }
787 void setRelaxAll(bool Value) { RelaxAll = Value; }
789 /// @name Section List Access
792 const SectionDataListType &getSectionList() const { return Sections; }
793 SectionDataListType &getSectionList() { return Sections; }
795 iterator begin() { return Sections.begin(); }
796 const_iterator begin() const { return Sections.begin(); }
798 iterator end() { return Sections.end(); }
799 const_iterator end() const { return Sections.end(); }
801 size_t size() const { return Sections.size(); }
804 /// @name Symbol List Access
807 const SymbolDataListType &getSymbolList() const { return Symbols; }
808 SymbolDataListType &getSymbolList() { return Symbols; }
810 symbol_iterator symbol_begin() { return Symbols.begin(); }
811 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
813 symbol_iterator symbol_end() { return Symbols.end(); }
814 const_symbol_iterator symbol_end() const { return Symbols.end(); }
816 size_t symbol_size() const { return Symbols.size(); }
819 /// @name Indirect Symbol List Access
822 // FIXME: This is a total hack, this should not be here. Once things are
823 // factored so that the streamer has direct access to the .o writer, it can
825 std::vector<IndirectSymbolData> &getIndirectSymbols() {
826 return IndirectSymbols;
829 indirect_symbol_iterator indirect_symbol_begin() {
830 return IndirectSymbols.begin();
832 const_indirect_symbol_iterator indirect_symbol_begin() const {
833 return IndirectSymbols.begin();
836 indirect_symbol_iterator indirect_symbol_end() {
837 return IndirectSymbols.end();
839 const_indirect_symbol_iterator indirect_symbol_end() const {
840 return IndirectSymbols.end();
843 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
846 /// @name Backend Data Access
849 MCSectionData &getSectionData(const MCSection &Section) const {
850 MCSectionData *Entry = SectionMap.lookup(&Section);
851 assert(Entry && "Missing section data!");
855 MCSectionData &getOrCreateSectionData(const MCSection &Section,
857 MCSectionData *&Entry = SectionMap[&Section];
859 if (Created) *Created = !Entry;
861 Entry = new MCSectionData(Section, this);
866 MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
867 MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
868 assert(Entry && "Missing symbol data!");
872 MCSymbolData &getOrCreateSymbolData(const MCSymbol &Symbol,
874 MCSymbolData *&Entry = SymbolMap[&Symbol];
876 if (Created) *Created = !Entry;
878 Entry = new MCSymbolData(Symbol, 0, 0, this);
888 } // end namespace llvm