MC: Move MCSectionData::Fixup out to MCAsmFixup.

llvm-svn: 95925
This commit is contained in:
Daniel Dunbar 2010-02-11 21:29:29 +00:00
parent b82b965968
commit fa324dd09b
2 changed files with 42 additions and 40 deletions

View File

@ -22,10 +22,39 @@ class raw_ostream;
class MCAssembler; class MCAssembler;
class MCContext; class MCContext;
class MCExpr; class MCExpr;
class MCFragment;
class MCSection; class MCSection;
class MCSectionData; class MCSectionData;
class MCSymbol; class MCSymbol;
/// MCAsmFixup - Represent a fixed size region of bytes inside some fragment
/// which needs to be rewritten. This region will either be rewritten by the
/// assembler or cause a relocation entry to be generated.
struct MCAsmFixup {
/// Fragment - The fragment containing the fixup.
MCFragment *Fragment;
/// Offset - The offset inside the fragment which needs to be rewritten.
uint64_t Offset;
/// Value - The expression to eventually write into the fragment.
const MCExpr *Value;
/// Size - The fixup size.
unsigned Size;
/// FixedValue - The value to replace the fix up by.
//
// FIXME: This should not be here.
uint64_t FixedValue;
public:
MCAsmFixup(MCFragment &_Fragment, uint64_t _Offset, const MCExpr &_Value,
unsigned _Size)
: Fragment(&_Fragment), Offset(_Offset), Value(&_Value), Size(_Size),
FixedValue(0) {}
};
class MCFragment : public ilist_node<MCFragment> { class MCFragment : public ilist_node<MCFragment> {
MCFragment(const MCFragment&); // DO NOT IMPLEMENT MCFragment(const MCFragment&); // DO NOT IMPLEMENT
void operator=(const MCFragment&); // DO NOT IMPLEMENT void operator=(const MCFragment&); // DO NOT IMPLEMENT
@ -284,41 +313,14 @@ class MCSectionData : public ilist_node<MCSectionData> {
void operator=(const MCSectionData&); // DO NOT IMPLEMENT void operator=(const MCSectionData&); // DO NOT IMPLEMENT
public: public:
/// Fixup - Represent a fixed size region of bytes inside some fragment which
/// needs to be rewritten. This region will either be rewritten by the
/// assembler or cause a relocation entry to be generated.
struct Fixup {
/// Fragment - The fragment containing the fixup.
MCFragment *Fragment;
/// Offset - The offset inside the fragment which needs to be rewritten.
uint64_t Offset;
/// Value - The expression to eventually write into the fragment.
const MCExpr *Value;
/// Size - The fixup size.
unsigned Size;
/// FixedValue - The value to replace the fix up by.
//
// FIXME: This should not be here.
uint64_t FixedValue;
public:
Fixup(MCFragment &_Fragment, uint64_t _Offset, const MCExpr &_Value,
unsigned _Size)
: Fragment(&_Fragment), Offset(_Offset), Value(&_Value), Size(_Size),
FixedValue(0) {}
};
typedef iplist<MCFragment> FragmentListType; typedef iplist<MCFragment> FragmentListType;
typedef FragmentListType::const_iterator const_iterator; typedef FragmentListType::const_iterator const_iterator;
typedef FragmentListType::iterator iterator; typedef FragmentListType::iterator iterator;
typedef std::vector<Fixup>::const_iterator const_fixup_iterator; typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator;
typedef std::vector<Fixup>::iterator fixup_iterator; typedef std::vector<MCAsmFixup>::iterator fixup_iterator;
private: private:
iplist<MCFragment> Fragments; iplist<MCFragment> Fragments;
@ -347,7 +349,7 @@ private:
mutable unsigned LastFixupLookup; mutable unsigned LastFixupLookup;
/// Fixups - The list of fixups in this section. /// Fixups - The list of fixups in this section.
std::vector<Fixup> Fixups; std::vector<MCAsmFixup> Fixups;
/// HasInstructions - Whether this section has had instructions emitted into /// HasInstructions - Whether this section has had instructions emitted into
/// it. /// it.
@ -385,7 +387,7 @@ public:
/// @name Fixup Access /// @name Fixup Access
/// @{ /// @{
std::vector<Fixup> &getFixups() { std::vector<MCAsmFixup> &getFixups() {
return Fixups; return Fixups;
} }
@ -413,7 +415,8 @@ public:
// //
// FIXME: This isn't horribly slow in practice, but there are much nicer // FIXME: This isn't horribly slow in practice, but there are much nicer
// solutions to applying the fixups. // solutions to applying the fixups.
const Fixup *LookupFixup(const MCFragment *Fragment, uint64_t Offset) const; const MCAsmFixup *LookupFixup(const MCFragment *Fragment,
uint64_t Offset) const;
uint64_t getAddress() const { uint64_t getAddress() const {
assert(Address != ~UINT64_C(0) && "Address not set!"); assert(Address != ~UINT64_C(0) && "Address not set!");

View File

@ -403,7 +403,7 @@ public:
uint32_t Word1; uint32_t Word1;
}; };
void ComputeScatteredRelocationInfo(MCAssembler &Asm, void ComputeScatteredRelocationInfo(MCAssembler &Asm,
MCSectionData::Fixup &Fixup, MCAsmFixup &Fixup,
const MCValue &Target, const MCValue &Target,
DenseMap<const MCSymbol*,MCSymbolData*> &SymbolMap, DenseMap<const MCSymbol*,MCSymbolData*> &SymbolMap,
std::vector<MachRelocationEntry> &Relocs) { std::vector<MachRelocationEntry> &Relocs) {
@ -454,7 +454,7 @@ public:
} }
void ComputeRelocationInfo(MCAssembler &Asm, void ComputeRelocationInfo(MCAssembler &Asm,
MCSectionData::Fixup &Fixup, MCAsmFixup &Fixup,
DenseMap<const MCSymbol*,MCSymbolData*> &SymbolMap, DenseMap<const MCSymbol*,MCSymbolData*> &SymbolMap,
std::vector<MachRelocationEntry> &Relocs) { std::vector<MachRelocationEntry> &Relocs) {
MCValue Target; MCValue Target;
@ -912,15 +912,15 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
A->getSectionList().push_back(this); A->getSectionList().push_back(this);
} }
const MCSectionData::Fixup * const MCAsmFixup *MCSectionData::LookupFixup(const MCFragment *Fragment,
MCSectionData::LookupFixup(const MCFragment *Fragment, uint64_t Offset) const { uint64_t Offset) const {
// Use a one level cache to turn the common case of accessing the fixups in // Use a one level cache to turn the common case of accessing the fixups in
// order into O(1) instead of O(N). // order into O(1) instead of O(N).
unsigned i = LastFixupLookup, Count = Fixups.size(), End = Fixups.size(); unsigned i = LastFixupLookup, Count = Fixups.size(), End = Fixups.size();
if (i >= End) if (i >= End)
i = 0; i = 0;
while (Count--) { while (Count--) {
const Fixup &F = Fixups[i]; const MCAsmFixup &F = Fixups[i];
if (F.Fragment == Fragment && F.Offset == Offset) { if (F.Fragment == Fragment && F.Offset == Offset) {
LastFixupLookup = i; LastFixupLookup = i;
return &F; return &F;
@ -998,8 +998,7 @@ void MCAssembler::LayoutSection(MCSectionData &SD) {
// Otherwise, add fixups for the values. // Otherwise, add fixups for the values.
for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) { for (uint64_t i = 0, e = FF.getCount(); i != e; ++i) {
MCSectionData::Fixup Fix(F, i * FF.getValueSize(), MCAsmFixup Fix(F, i*FF.getValueSize(), FF.getValue(),FF.getValueSize());
FF.getValue(),FF.getValueSize());
SD.getFixups().push_back(Fix); SD.getFixups().push_back(Fix);
} }
break; break;
@ -1107,7 +1106,7 @@ static void WriteFileData(raw_ostream &OS, const MCFragment &F,
// Find the fixup. // Find the fixup.
// //
// FIXME: Find a better way to write in the fixes. // FIXME: Find a better way to write in the fixes.
const MCSectionData::Fixup *Fixup = const MCAsmFixup *Fixup =
F.getParent()->LookupFixup(&F, i * FF.getValueSize()); F.getParent()->LookupFixup(&F, i * FF.getValueSize());
assert(Fixup && "Missing fixup for fill value!"); assert(Fixup && "Missing fixup for fill value!");
Value = Fixup->FixedValue; Value = Fixup->FixedValue;