MC: Eliminate MCAsmFixup, replace with MCFixup.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104699 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2010-05-26 15:18:56 +00:00
parent 0dd0c941c9
commit c90e30aa6f
8 changed files with 44 additions and 75 deletions

View File

@@ -36,33 +36,6 @@ class MCSymbolData;
class MCValue; class MCValue;
class TargetAsmBackend; class TargetAsmBackend;
/// 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.
//
// FIXME: This should probably just be merged with MCFixup.
class MCAsmFixup {
/// 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;
/// Kind - The fixup kind.
MCFixupKind Kind;
public:
MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, MCFixupKind _Kind)
: Offset(_Offset), Value(&_Value), Kind(_Kind) {}
MCFixupKind getKind() const { return MCFixupKind(Kind); }
uint64_t getOffset() const { return Offset; }
void setOffset(uint64_t Value) { Offset = Value; }
const MCExpr *getValue() const { return Value; }
};
class MCFragment : public ilist_node<MCFragment> { class MCFragment : public ilist_node<MCFragment> {
friend class MCAsmLayout; friend class MCAsmLayout;
@@ -135,11 +108,11 @@ class MCDataFragment : public MCFragment {
SmallString<32> Contents; SmallString<32> Contents;
/// Fixups - The list of fixups in this fragment. /// Fixups - The list of fixups in this fragment.
std::vector<MCAsmFixup> Fixups; std::vector<MCFixup> Fixups;
public: public:
typedef std::vector<MCAsmFixup>::const_iterator const_fixup_iterator; typedef std::vector<MCFixup>::const_iterator const_fixup_iterator;
typedef std::vector<MCAsmFixup>::iterator fixup_iterator; typedef std::vector<MCFixup>::iterator fixup_iterator;
public: public:
MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {} MCDataFragment(MCSectionData *SD = 0) : MCFragment(FT_Data, SD) {}
@@ -154,15 +127,15 @@ public:
/// @name Fixup Access /// @name Fixup Access
/// @{ /// @{
void addFixup(MCAsmFixup Fixup) { void addFixup(MCFixup Fixup) {
// Enforce invariant that fixups are in offset order. // Enforce invariant that fixups are in offset order.
assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) && assert((Fixups.empty() || Fixup.getOffset() > Fixups.back().getOffset()) &&
"Fixups must be added in order!"); "Fixups must be added in order!");
Fixups.push_back(Fixup); Fixups.push_back(Fixup);
} }
std::vector<MCAsmFixup> &getFixups() { return Fixups; } std::vector<MCFixup> &getFixups() { return Fixups; }
const std::vector<MCAsmFixup> &getFixups() const { return Fixups; } const std::vector<MCFixup> &getFixups() const { return Fixups; }
fixup_iterator fixup_begin() { return Fixups.begin(); } fixup_iterator fixup_begin() { return Fixups.begin(); }
const_fixup_iterator fixup_begin() const { return Fixups.begin(); } const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
@@ -193,11 +166,11 @@ class MCInstFragment : public MCFragment {
SmallString<8> Code; SmallString<8> Code;
/// Fixups - The list of fixups in this fragment. /// Fixups - The list of fixups in this fragment.
SmallVector<MCAsmFixup, 1> Fixups; SmallVector<MCFixup, 1> Fixups;
public: public:
typedef SmallVectorImpl<MCAsmFixup>::const_iterator const_fixup_iterator; typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
typedef SmallVectorImpl<MCAsmFixup>::iterator fixup_iterator; typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
public: public:
MCInstFragment(MCInst _Inst, MCSectionData *SD = 0) MCInstFragment(MCInst _Inst, MCSectionData *SD = 0)
@@ -221,8 +194,8 @@ public:
/// @name Fixup Access /// @name Fixup Access
/// @{ /// @{
SmallVectorImpl<MCAsmFixup> &getFixups() { return Fixups; } SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
const SmallVectorImpl<MCAsmFixup> &getFixups() const { return Fixups; } const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
fixup_iterator fixup_begin() { return Fixups.begin(); } fixup_iterator fixup_begin() { return Fixups.begin(); }
const_fixup_iterator fixup_begin() const { return Fixups.begin(); } const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
@@ -633,12 +606,12 @@ private:
/// \arg Value result is fixed, otherwise the value may change due to /// \arg Value result is fixed, otherwise the value may change due to
/// relocation. /// relocation.
bool EvaluateFixup(const MCAsmLayout &Layout, bool EvaluateFixup(const MCAsmLayout &Layout,
const MCAsmFixup &Fixup, const MCFragment *DF, const MCFixup &Fixup, const MCFragment *DF,
MCValue &Target, uint64_t &Value) const; MCValue &Target, uint64_t &Value) const;
/// Check whether a fixup can be satisfied, or whether it needs to be relaxed /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
/// (increased in size, in order to hold its value correctly). /// (increased in size, in order to hold its value correctly).
bool FixupNeedsRelaxation(const MCAsmFixup &Fixup, const MCFragment *DF, bool FixupNeedsRelaxation(const MCFixup &Fixup, const MCFragment *DF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
/// Check whether the given fragment needs relaxation. /// Check whether the given fragment needs relaxation.

View File

@@ -15,9 +15,9 @@
#include <cassert> #include <cassert>
namespace llvm { namespace llvm {
class MCAsmFixup;
class MCAsmLayout; class MCAsmLayout;
class MCAssembler; class MCAssembler;
class MCFixup;
class MCFragment; class MCFragment;
class MCValue; class MCValue;
class raw_ostream; class raw_ostream;
@@ -72,7 +72,7 @@ public:
virtual void RecordRelocation(const MCAssembler &Asm, virtual void RecordRelocation(const MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) = 0; uint64_t &FixedValue) = 0;
/// Write the object file. /// Write the object file.

View File

@@ -15,9 +15,9 @@
#include <cassert> #include <cassert>
namespace llvm { namespace llvm {
class MCAsmFixup;
class MCAssembler; class MCAssembler;
class MCFragment; class MCFragment;
class MCFixup;
class MCValue; class MCValue;
class raw_ostream; class raw_ostream;
@@ -33,7 +33,7 @@ public:
virtual void RecordRelocation(const MCAssembler &Asm, virtual void RecordRelocation(const MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue); uint64_t &FixedValue);
virtual void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout); virtual void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout);

View File

@@ -13,8 +13,8 @@
#include "llvm/System/DataTypes.h" #include "llvm/System/DataTypes.h"
namespace llvm { namespace llvm {
class MCAsmFixup;
class MCDataFragment; class MCDataFragment;
class MCFixup;
class MCInst; class MCInst;
class MCInstFragment; class MCInstFragment;
class MCObjectWriter; class MCObjectWriter;
@@ -105,7 +105,7 @@ public:
/// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
/// data fragment, at the offset specified by the fixup and following the /// data fragment, at the offset specified by the fixup and following the
/// fixup kind as appropriate. /// fixup kind as appropriate.
virtual void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &Fragment, virtual void ApplyFixup(const MCFixup &Fixup, MCDataFragment &Fragment,
uint64_t Value) const = 0; uint64_t Value) const = 0;
/// MayNeedRelaxation - Check whether the given instruction may need /// MayNeedRelaxation - Check whether the given instruction may need
@@ -115,7 +115,7 @@ public:
/// \arg Fixups - The actual fixups this instruction encoded to, for potential /// \arg Fixups - The actual fixups this instruction encoded to, for potential
/// use by the target backend. /// use by the target backend.
virtual bool MayNeedRelaxation(const MCInst &Inst, virtual bool MayNeedRelaxation(const MCInst &Inst,
const SmallVectorImpl<MCAsmFixup> &Fixups) const = 0; const SmallVectorImpl<MCFixup> &Fixups) const = 0;
/// RelaxInstruction - Relax the instruction in the given fragment to the next /// RelaxInstruction - Relax the instruction in the given fragment to the next
/// wider instruction. /// wider instruction.

View File

@@ -226,7 +226,7 @@ MCAssembler::~MCAssembler() {
} }
static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm, static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
const MCAsmFixup &Fixup, const MCFixup &Fixup,
const MCValue Target, const MCValue Target,
const MCSection *BaseSection) { const MCSection *BaseSection) {
// The effective fixup address is // The effective fixup address is
@@ -264,7 +264,7 @@ static bool isScatteredFixupFullyResolvedSimple(const MCAssembler &Asm,
static bool isScatteredFixupFullyResolved(const MCAssembler &Asm, static bool isScatteredFixupFullyResolved(const MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCAsmFixup &Fixup, const MCFixup &Fixup,
const MCValue Target, const MCValue Target,
const MCSymbolData *BaseSymbol) { const MCSymbolData *BaseSymbol) {
// The effective fixup address is // The effective fixup address is
@@ -343,7 +343,7 @@ const MCSymbolData *MCAssembler::getAtom(const MCAsmLayout &Layout,
} }
bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout, bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
const MCAsmFixup &Fixup, const MCFragment *DF, const MCFixup &Fixup, const MCFragment *DF,
MCValue &Target, uint64_t &Value) const { MCValue &Target, uint64_t &Value) const {
++stats::EvaluateFixup; ++stats::EvaluateFixup;
@@ -740,7 +740,7 @@ void MCAssembler::Finish() {
for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(), for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
ie3 = DF->fixup_end(); it3 != ie3; ++it3) { ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
MCAsmFixup &Fixup = *it3; MCFixup &Fixup = *it3;
// Evaluate the fixup. // Evaluate the fixup.
MCValue Target; MCValue Target;
@@ -764,7 +764,7 @@ void MCAssembler::Finish() {
stats::ObjectBytes += OS.tell() - StartOffset; stats::ObjectBytes += OS.tell() - StartOffset;
} }
bool MCAssembler::FixupNeedsRelaxation(const MCAsmFixup &Fixup, bool MCAssembler::FixupNeedsRelaxation(const MCFixup &Fixup,
const MCFragment *DF, const MCFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
if (getRelaxAll()) if (getRelaxAll())
@@ -841,11 +841,9 @@ bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
IF->setInst(Relaxed); IF->setInst(Relaxed);
IF->getCode() = Code; IF->getCode() = Code;
IF->getFixups().clear(); IF->getFixups().clear();
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { // FIXME: Eliminate copy.
MCFixup &F = Fixups[i]; for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
IF->getFixups().push_back(MCAsmFixup(F.getOffset(), *F.getValue(), IF->getFixups().push_back(Fixups[i]);
F.getKind()));
}
// Update the layout, and remember that we relaxed. If we are relaxing // Update the layout, and remember that we relaxed. If we are relaxing
// everything, we can skip this step since nothing will depend on updating // everything, we can skip this step since nothing will depend on updating
@@ -904,8 +902,8 @@ void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
namespace llvm { namespace llvm {
raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) { raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) {
OS << "<MCAsmFixup" << " Offset:" << AF.getOffset() OS << "<MCFixup" << " Offset:" << AF.getOffset()
<< " Value:" << *AF.getValue() << " Value:" << *AF.getValue()
<< " Kind:" << AF.getKind() << ">"; << " Kind:" << AF.getKind() << ">";
return OS; return OS;

View File

@@ -376,8 +376,9 @@ void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
for (unsigned i = 0; i != Size; ++i) for (unsigned i = 0; i != Size; ++i)
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8))); DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
} else { } else {
DF->addFixup(MCAsmFixup(DF->getContents().size(), *AddValueSymbols(Value), DF->addFixup(MCFixup::Create(DF->getContents().size(),
MCFixup::getKindForSize(Size))); AddValueSymbols(Value),
MCFixup::getKindForSize(Size)));
DF->getContents().resize(DF->getContents().size() + Size, 0); DF->getContents().resize(DF->getContents().size() + Size, 0);
} }
} }
@@ -434,12 +435,9 @@ void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
VecOS.flush(); VecOS.flush();
// FIXME: Eliminate this copy. // FIXME: Eliminate this copy.
SmallVector<MCAsmFixup, 4> AsmFixups; SmallVector<MCFixup, 4> AsmFixups;
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
MCFixup &F = Fixups[i]; AsmFixups.push_back(Fixups[i]);
AsmFixups.push_back(MCAsmFixup(F.getOffset(), *F.getValue(),
F.getKind()));
}
// See if we might need to relax this instruction, if so it needs its own // See if we might need to relax this instruction, if so it needs its own
// fragment. // fragment.

View File

@@ -472,7 +472,7 @@ public:
void RecordX86_64Relocation(const MCAssembler &Asm, const MCAsmLayout &Layout, void RecordX86_64Relocation(const MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) { uint64_t &FixedValue) {
unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind()); unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind());
unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind()); unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind());
@@ -682,7 +682,7 @@ public:
void RecordScatteredRelocation(const MCAssembler &Asm, void RecordScatteredRelocation(const MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) { uint64_t &FixedValue) {
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset(); uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind()); unsigned IsPCRel = isFixupKindPCRel(Fixup.getKind());
@@ -739,7 +739,7 @@ public:
} }
void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout, void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCAsmFixup &Fixup, const MCFragment *Fragment, const MCFixup &Fixup,
MCValue Target, uint64_t &FixedValue) { MCValue Target, uint64_t &FixedValue) {
if (Is64Bit) { if (Is64Bit) {
RecordX86_64Relocation(Asm, Layout, Fragment, Fixup, Target, FixedValue); RecordX86_64Relocation(Asm, Layout, Fragment, Fixup, Target, FixedValue);
@@ -1168,7 +1168,7 @@ void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
void MachObjectWriter::RecordRelocation(const MCAssembler &Asm, void MachObjectWriter::RecordRelocation(const MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCAsmFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) { uint64_t &FixedValue) {
((MachObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup, ((MachObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup,
Target, FixedValue); Target, FixedValue);

View File

@@ -44,7 +44,7 @@ public:
X86AsmBackend(const Target &T) X86AsmBackend(const Target &T)
: TargetAsmBackend(T) {} : TargetAsmBackend(T) {}
void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF, void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
uint64_t Value) const { uint64_t Value) const {
unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind()); unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind());
@@ -55,7 +55,7 @@ public:
} }
bool MayNeedRelaxation(const MCInst &Inst, bool MayNeedRelaxation(const MCInst &Inst,
const SmallVectorImpl<MCAsmFixup> &Fixups) const; const SmallVectorImpl<MCFixup> &Fixups) const;
void RelaxInstruction(const MCInstFragment *IF, MCInst &Res) const; void RelaxInstruction(const MCInstFragment *IF, MCInst &Res) const;
@@ -89,9 +89,9 @@ static unsigned getRelaxedOpcode(unsigned Op) {
} }
bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst, bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst,
const SmallVectorImpl<MCAsmFixup> &Fixups) const { const SmallVectorImpl<MCFixup> &Fixups) const {
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) { for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
const MCAsmFixup &F = Fixups[i]; const MCFixup &F = Fixups[i];
// We don't support relaxing anything else currently. Make sure we error out // We don't support relaxing anything else currently. Make sure we error out
// if we see a non-constant 1 or 2 byte fixup. // if we see a non-constant 1 or 2 byte fixup.