Renamed MCInstFragment to MCRelaxableFragment and added some comments.

No change in functionality.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171822 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Bendersky 2013-01-08 00:22:56 +00:00
parent 72a81be374
commit 251040bc18
12 changed files with 54 additions and 47 deletions

View File

@ -22,7 +22,7 @@ class MCELFObjectTargetWriter;
struct MCFixupKindInfo; struct MCFixupKindInfo;
class MCFragment; class MCFragment;
class MCInst; class MCInst;
class MCInstFragment; class MCRelaxableFragment;
class MCObjectWriter; class MCObjectWriter;
class MCSection; class MCSection;
class MCValue; class MCValue;
@ -130,7 +130,7 @@ public:
/// fixup requires the associated instruction to be relaxed. /// fixup requires the associated instruction to be relaxed.
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const = 0; const MCAsmLayout &Layout) const = 0;
/// RelaxInstruction - Relax the instruction in the given fragment to the next /// RelaxInstruction - Relax the instruction in the given fragment to the next

View File

@ -48,7 +48,7 @@ public:
FT_Align, FT_Align,
FT_Data, FT_Data,
FT_Fill, FT_Fill,
FT_Inst, FT_Relaxable,
FT_Org, FT_Org,
FT_Dwarf, FT_Dwarf,
FT_DwarfFrame, FT_DwarfFrame,
@ -158,10 +158,12 @@ public:
static bool classof(const MCFragment *F) { static bool classof(const MCFragment *F) {
MCFragment::FragmentType Kind = F->getKind(); MCFragment::FragmentType Kind = F->getKind();
return Kind == MCFragment::FT_Inst || Kind == MCFragment::FT_Data; return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data;
} }
}; };
/// Fragment for data and encoded instructions.
///
class MCDataFragment : public MCEncodedFragment { class MCDataFragment : public MCEncodedFragment {
virtual void anchor(); virtual void anchor();
@ -210,7 +212,10 @@ public:
} }
}; };
class MCInstFragment : public MCEncodedFragment { /// A relaxable fragment holds on to its MCInst, since it may need to be
/// relaxed during the assembler layout and relaxation stage.
///
class MCRelaxableFragment : public MCEncodedFragment {
virtual void anchor(); virtual void anchor();
/// Inst - The instruction this is a fragment for. /// Inst - The instruction this is a fragment for.
@ -223,8 +228,8 @@ class MCInstFragment : public MCEncodedFragment {
SmallVector<MCFixup, 1> Fixups; SmallVector<MCFixup, 1> Fixups;
public: public:
MCInstFragment(const MCInst &_Inst, MCSectionData *SD = 0) MCRelaxableFragment(const MCInst &_Inst, MCSectionData *SD = 0)
: MCEncodedFragment(FT_Inst, SD), Inst(_Inst) { : MCEncodedFragment(FT_Relaxable, SD), Inst(_Inst) {
} }
virtual SmallVectorImpl<char> &getContents() { return Contents; } virtual SmallVectorImpl<char> &getContents() { return Contents; }
@ -251,7 +256,7 @@ public:
const_fixup_iterator fixup_end() const {return Fixups.end();} const_fixup_iterator fixup_end() const {return Fixups.end();}
static bool classof(const MCFragment *F) { static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Inst; return F->getKind() == MCFragment::FT_Relaxable;
} }
}; };
@ -817,11 +822,11 @@ private:
/// 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 MCFixup &Fixup, const MCInstFragment *DF, bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
/// Check whether the given fragment needs relaxation. /// Check whether the given fragment needs relaxation.
bool fragmentNeedsRelaxation(const MCInstFragment *IF, bool fragmentNeedsRelaxation(const MCRelaxableFragment *IF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
/// \brief Perform one layout iteration and return true if any offsets /// \brief Perform one layout iteration and return true if any offsets
@ -832,7 +837,7 @@ private:
/// if any offsets were adjusted. /// if any offsets were adjusted.
bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD); bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
bool relaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF); bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF); bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);

View File

@ -390,8 +390,8 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
return cast<MCDataFragment>(F).getContents().size(); return cast<MCDataFragment>(F).getContents().size();
case MCFragment::FT_Fill: case MCFragment::FT_Fill:
return cast<MCFillFragment>(F).getSize(); return cast<MCFillFragment>(F).getSize();
case MCFragment::FT_Inst: case MCFragment::FT_Relaxable:
return cast<MCInstFragment>(F).getInstSize(); return cast<MCRelaxableFragment>(F).getInstSize();
case MCFragment::FT_LEB: case MCFragment::FT_LEB:
return cast<MCLEBFragment>(F).getContents().size(); return cast<MCLEBFragment>(F).getContents().size();
@ -566,7 +566,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
writeFragmentContents(F, OW); writeFragmentContents(F, OW);
break; break;
case MCFragment::FT_Inst: case MCFragment::FT_Relaxable:
++stats::EmittedInstFragments; ++stats::EmittedInstFragments;
writeFragmentContents(F, OW); writeFragmentContents(F, OW);
break; break;
@ -763,7 +763,7 @@ void MCAssembler::Finish() {
} }
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup, bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// If we cannot resolve the fixup value, it requires relaxation. // If we cannot resolve the fixup value, it requires relaxation.
MCValue Target; MCValue Target;
@ -774,25 +774,25 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout); return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout);
} }
bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF, bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// If this inst doesn't ever need relaxation, ignore it. This occurs when we // If this inst doesn't ever need relaxation, ignore it. This occurs when we
// are intentionally pushing out inst fragments, or because we relaxed a // are intentionally pushing out inst fragments, or because we relaxed a
// previous instruction to one that doesn't need relaxation. // previous instruction to one that doesn't need relaxation.
if (!getBackend().mayNeedRelaxation(IF->getInst())) if (!getBackend().mayNeedRelaxation(F->getInst()))
return false; return false;
for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(), for (MCRelaxableFragment::const_fixup_iterator it = F->fixup_begin(),
ie = IF->fixup_end(); it != ie; ++it) ie = F->fixup_end(); it != ie; ++it)
if (fixupNeedsRelaxation(*it, IF, Layout)) if (fixupNeedsRelaxation(*it, F, Layout))
return true; return true;
return false; return false;
} }
bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
MCInstFragment &IF) { MCRelaxableFragment &F) {
if (!fragmentNeedsRelaxation(&IF, Layout)) if (!fragmentNeedsRelaxation(&F, Layout))
return false; return false;
++stats::RelaxedInstructions; ++stats::RelaxedInstructions;
@ -803,7 +803,7 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
// Relax the fragment. // Relax the fragment.
MCInst Relaxed; MCInst Relaxed;
getBackend().relaxInstruction(IF.getInst(), Relaxed); getBackend().relaxInstruction(F.getInst(), Relaxed);
// Encode the new instruction. // Encode the new instruction.
// //
@ -815,10 +815,10 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups); getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups);
VecOS.flush(); VecOS.flush();
// Update the instruction fragment. // Update the fragment.
IF.setInst(Relaxed); F.setInst(Relaxed);
IF.getContents() = Code; F.getContents() = Code;
IF.getFixups() = Fixups; F.getFixups() = Fixups;
return true; return true;
} }
@ -886,10 +886,10 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
switch(I->getKind()) { switch(I->getKind()) {
default: default:
break; break;
case MCFragment::FT_Inst: case MCFragment::FT_Relaxable:
assert(!getRelaxAll() && assert(!getRelaxAll() &&
"Did not expect a MCInstFragment in RelaxAll mode"); "Did not expect a MCRelaxableFragment in RelaxAll mode");
RelaxedFrag = relaxInstruction(Layout, *cast<MCInstFragment>(I)); RelaxedFrag = relaxInstruction(Layout, *cast<MCRelaxableFragment>(I));
break; break;
case MCFragment::FT_Dwarf: case MCFragment::FT_Dwarf:
RelaxedFrag = relaxDwarfLineAddr(Layout, RelaxedFrag = relaxDwarfLineAddr(Layout,
@ -956,7 +956,7 @@ void MCFragment::dump() {
case MCFragment::FT_Align: OS << "MCAlignFragment"; break; case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
case MCFragment::FT_Data: OS << "MCDataFragment"; break; case MCFragment::FT_Data: OS << "MCDataFragment"; break;
case MCFragment::FT_Fill: OS << "MCFillFragment"; break; case MCFragment::FT_Fill: OS << "MCFillFragment"; break;
case MCFragment::FT_Inst: OS << "MCInstFragment"; break; case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break;
case MCFragment::FT_Org: OS << "MCOrgFragment"; break; case MCFragment::FT_Org: OS << "MCOrgFragment"; break;
case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break; case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break; case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
@ -1008,11 +1008,11 @@ void MCFragment::dump() {
<< " Size:" << FF->getSize(); << " Size:" << FF->getSize();
break; break;
} }
case MCFragment::FT_Inst: { case MCFragment::FT_Relaxable: {
const MCInstFragment *IF = cast<MCInstFragment>(this); const MCRelaxableFragment *F = cast<MCRelaxableFragment>(this);
OS << "\n "; OS << "\n ";
OS << " Inst:"; OS << " Inst:";
IF->getInst().dump_pretty(OS); F->getInst().dump_pretty(OS);
break; break;
} }
case MCFragment::FT_Org: { case MCFragment::FT_Org: {
@ -1096,7 +1096,7 @@ void MCAssembler::dump() {
// anchors for MC*Fragment vtables // anchors for MC*Fragment vtables
void MCEncodedFragment::anchor() { } void MCEncodedFragment::anchor() { }
void MCDataFragment::anchor() { } void MCDataFragment::anchor() { }
void MCInstFragment::anchor() { } void MCRelaxableFragment::anchor() { }
void MCAlignFragment::anchor() { } void MCAlignFragment::anchor() { }
void MCFillFragment::anchor() { } void MCFillFragment::anchor() { }
void MCOrgFragment::anchor() { } void MCOrgFragment::anchor() { }

View File

@ -343,7 +343,7 @@ void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) { void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
this->MCObjectStreamer::EmitInstToFragment(Inst); this->MCObjectStreamer::EmitInstToFragment(Inst);
MCInstFragment &F = *cast<MCInstFragment>(getCurrentFragment()); MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i) for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
fixSymbolsInTLSFixups(F.getFixups()[i].getValue()); fixSymbolsInTLSFixups(F.getFixups()[i].getValue());

View File

@ -217,7 +217,8 @@ void MCObjectStreamer::EmitInstruction(const MCInst &Inst) {
void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst) { void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst) {
// Always create a new, separate fragment here, because its size can change // Always create a new, separate fragment here, because its size can change
// during relaxation. // during relaxation.
MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData()); MCRelaxableFragment *IF =
new MCRelaxableFragment(Inst, getCurrentSectionData());
SmallString<128> Code; SmallString<128> Code;
raw_svector_ostream VecOS(Code); raw_svector_ostream VecOS(Code);

View File

@ -188,7 +188,8 @@ bool MCPureStreamer::EmitValueToOffset(const MCExpr *Offset,
} }
void MCPureStreamer::EmitInstToFragment(const MCInst &Inst) { void MCPureStreamer::EmitInstToFragment(const MCInst &Inst) {
MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData()); MCRelaxableFragment *IF =
new MCRelaxableFragment(Inst, getCurrentSectionData());
// Add the fixups and data. // Add the fixups and data.
// //

View File

@ -122,7 +122,7 @@ public:
bool fixupNeedsRelaxation(const MCFixup &Fixup, bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
void relaxInstruction(const MCInst &Inst, MCInst &Res) const; void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
@ -165,7 +165,7 @@ bool ARMAsmBackend::mayNeedRelaxation(const MCInst &Inst) const {
bool ARMAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup, bool ARMAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
switch ((unsigned)Fixup.getKind()) { switch ((unsigned)Fixup.getKind()) {
case ARM::fixup_arm_thumb_br: { case ARM::fixup_arm_thumb_br: {

View File

@ -54,7 +54,7 @@ public:
bool fixupNeedsRelaxation(const MCFixup &Fixup, bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
void relaxInstruction(const MCInst &Inst, MCInst &Res) const; void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
@ -88,7 +88,7 @@ bool MBlazeAsmBackend::mayNeedRelaxation(const MCInst &Inst) const {
bool MBlazeAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup, bool MBlazeAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// FIXME: Is this right? It's what the "generic" code was doing before, // FIXME: Is this right? It's what the "generic" code was doing before,
// but is X86 specific. Is it actually true for MBlaze also, or was it // but is X86 specific. Is it actually true for MBlaze also, or was it

View File

@ -213,7 +213,7 @@ public:
/// fixup requires the associated instruction to be relaxed. /// fixup requires the associated instruction to be relaxed.
bool fixupNeedsRelaxation(const MCFixup &Fixup, bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// FIXME. // FIXME.
assert(0 && "RelaxInstruction() unimplemented"); assert(0 && "RelaxInstruction() unimplemented");

View File

@ -119,7 +119,7 @@ public:
bool fixupNeedsRelaxation(const MCFixup &Fixup, bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// FIXME. // FIXME.
llvm_unreachable("relaxInstruction() unimplemented"); llvm_unreachable("relaxInstruction() unimplemented");

View File

@ -49,7 +49,7 @@ public:
virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
uint64_t Value) const; uint64_t Value) const;
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
return false; return false;
} }

View File

@ -113,7 +113,7 @@ public:
bool fixupNeedsRelaxation(const MCFixup &Fixup, bool fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
void relaxInstruction(const MCInst &Inst, MCInst &Res) const; void relaxInstruction(const MCInst &Inst, MCInst &Res) const;
@ -255,7 +255,7 @@ bool X86AsmBackend::mayNeedRelaxation(const MCInst &Inst) const {
bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup, bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
uint64_t Value, uint64_t Value,
const MCInstFragment *DF, const MCRelaxableFragment *DF,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
// Relax if the value is too big for a (signed) i8. // Relax if the value is too big for a (signed) i8.
return int64_t(Value) != int64_t(int8_t(Value)); return int64_t(Value) != int64_t(int8_t(Value));