mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-30 17:33:24 +00:00
Make naming consistent, add comments and sanity asserts
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170007 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9c08510696
commit
d52a2c0a31
@ -39,14 +39,15 @@ private:
|
|||||||
|
|
||||||
/// The last fragment which was laid out, or 0 if nothing has been laid
|
/// The last fragment which was laid out, or 0 if nothing has been laid
|
||||||
/// out. Fragments are always laid out in order, so all fragments with a
|
/// out. Fragments are always laid out in order, so all fragments with a
|
||||||
/// lower ordinal will be up to date.
|
/// lower ordinal will be valid.
|
||||||
mutable DenseMap<const MCSectionData*, MCFragment *> LastValidFragment;
|
mutable DenseMap<const MCSectionData*, MCFragment*> LastValidFragment;
|
||||||
|
|
||||||
/// \brief Make sure that the layout for the given fragment is valid, lazily
|
/// \brief Make sure that the layout for the given fragment is valid, lazily
|
||||||
/// computing it if necessary.
|
/// computing it if necessary.
|
||||||
void EnsureValid(const MCFragment *F) const;
|
void ensureValid(const MCFragment *F) const;
|
||||||
|
|
||||||
bool isFragmentUpToDate(const MCFragment *F) const;
|
/// \brief Is the layout for this fragment valid?
|
||||||
|
bool isFragmentValid(const MCFragment *F) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCAsmLayout(MCAssembler &_Assembler);
|
MCAsmLayout(MCAssembler &_Assembler);
|
||||||
@ -61,7 +62,7 @@ public:
|
|||||||
/// \brief Perform layout for a single fragment, assuming that the previous
|
/// \brief Perform layout for a single fragment, assuming that the previous
|
||||||
/// fragment has already been laid out correctly, and the parent section has
|
/// fragment has already been laid out correctly, and the parent section has
|
||||||
/// been initialized.
|
/// been initialized.
|
||||||
void LayoutFragment(MCFragment *Fragment);
|
void layoutFragment(MCFragment *Fragment);
|
||||||
|
|
||||||
/// @name Section Access (in layout order)
|
/// @name Section Access (in layout order)
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -71,7 +71,7 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
|
|||||||
SectionOrder.push_back(&*it);
|
SectionOrder.push_back(&*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const {
|
bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
|
||||||
const MCSectionData &SD = *F->getParent();
|
const MCSectionData &SD = *F->getParent();
|
||||||
const MCFragment *LastValid = LastValidFragment.lookup(&SD);
|
const MCFragment *LastValid = LastValidFragment.lookup(&SD);
|
||||||
if (!LastValid)
|
if (!LastValid)
|
||||||
@ -81,8 +81,8 @@ bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) {
|
void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) {
|
||||||
// If this fragment wasn't already up-to-date, we don't need to do anything.
|
// If this fragment wasn't already valid, we don't need to do anything.
|
||||||
if (!isFragmentUpToDate(F))
|
if (!isFragmentValid(F))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise, reset the last valid fragment to this fragment.
|
// Otherwise, reset the last valid fragment to this fragment.
|
||||||
@ -90,7 +90,7 @@ void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) {
|
|||||||
LastValidFragment[&SD] = F;
|
LastValidFragment[&SD] = F;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmLayout::EnsureValid(const MCFragment *F) const {
|
void MCAsmLayout::ensureValid(const MCFragment *F) const {
|
||||||
MCSectionData &SD = *F->getParent();
|
MCSectionData &SD = *F->getParent();
|
||||||
|
|
||||||
MCFragment *Cur = LastValidFragment[&SD];
|
MCFragment *Cur = LastValidFragment[&SD];
|
||||||
@ -99,15 +99,16 @@ void MCAsmLayout::EnsureValid(const MCFragment *F) const {
|
|||||||
else
|
else
|
||||||
Cur = Cur->getNextNode();
|
Cur = Cur->getNextNode();
|
||||||
|
|
||||||
// Advance the layout position until the fragment is up-to-date.
|
// Advance the layout position until the fragment is valid.
|
||||||
while (!isFragmentUpToDate(F)) {
|
while (!isFragmentValid(F)) {
|
||||||
const_cast<MCAsmLayout*>(this)->LayoutFragment(Cur);
|
assert(Cur && "Layout bookkeeping error");
|
||||||
|
const_cast<MCAsmLayout*>(this)->layoutFragment(Cur);
|
||||||
Cur = Cur->getNextNode();
|
Cur = Cur->getNextNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
|
uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
|
||||||
EnsureValid(F);
|
ensureValid(F);
|
||||||
assert(F->Offset != ~UINT64_C(0) && "Address not set!");
|
assert(F->Offset != ~UINT64_C(0) && "Address not set!");
|
||||||
return F->Offset;
|
return F->Offset;
|
||||||
}
|
}
|
||||||
@ -374,15 +375,15 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
|
|||||||
llvm_unreachable("invalid fragment kind");
|
llvm_unreachable("invalid fragment kind");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmLayout::LayoutFragment(MCFragment *F) {
|
void MCAsmLayout::layoutFragment(MCFragment *F) {
|
||||||
MCFragment *Prev = F->getPrevNode();
|
MCFragment *Prev = F->getPrevNode();
|
||||||
|
|
||||||
// We should never try to recompute something which is up-to-date.
|
// We should never try to recompute something which is valid.
|
||||||
assert(!isFragmentUpToDate(F) && "Attempt to recompute up-to-date fragment!");
|
assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
|
||||||
// We should never try to compute the fragment layout if it's predecessor
|
// We should never try to compute the fragment layout if its predecessor
|
||||||
// isn't up-to-date.
|
// isn't valid.
|
||||||
assert((!Prev || isFragmentUpToDate(Prev)) &&
|
assert((!Prev || isFragmentValid(Prev)) &&
|
||||||
"Attempt to compute fragment before it's predecessor!");
|
"Attempt to compute fragment before its predecessor!");
|
||||||
|
|
||||||
++stats::FragmentLayouts;
|
++stats::FragmentLayouts;
|
||||||
|
|
||||||
@ -605,9 +606,9 @@ void MCAssembler::Finish() {
|
|||||||
SD->setLayoutOrder(i);
|
SD->setLayoutOrder(i);
|
||||||
|
|
||||||
unsigned FragmentIndex = 0;
|
unsigned FragmentIndex = 0;
|
||||||
for (MCSectionData::iterator it2 = SD->begin(),
|
for (MCSectionData::iterator iFrag = SD->begin(), iFragEnd = SD->end();
|
||||||
ie2 = SD->end(); it2 != ie2; ++it2)
|
iFrag != iFragEnd; ++iFrag)
|
||||||
it2->setLayoutOrder(FragmentIndex++);
|
iFrag->setLayoutOrder(FragmentIndex++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout until everything fits.
|
// Layout until everything fits.
|
||||||
@ -767,9 +768,11 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
|
|||||||
bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
|
bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
|
||||||
// Holds the first fragment which needed relaxing during this layout. It will
|
// Holds the first fragment which needed relaxing during this layout. It will
|
||||||
// remain NULL if none were relaxed.
|
// remain NULL if none were relaxed.
|
||||||
MCFragment *FirstInvalidFragment = NULL;
|
// When a fragment is relaxed, all the fragments following it should get
|
||||||
|
// invalidated because their offset is going to change.
|
||||||
|
MCFragment *FirstRelaxedFragment = NULL;
|
||||||
|
|
||||||
// Scan for fragments that need relaxation.
|
// Attempt to relax all the fragments in the section.
|
||||||
for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) {
|
for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) {
|
||||||
// Check if this is a fragment that needs relaxation.
|
// Check if this is a fragment that needs relaxation.
|
||||||
bool RelaxedFrag = false;
|
bool RelaxedFrag = false;
|
||||||
@ -794,11 +797,11 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
|
|||||||
RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
|
RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (RelaxedFrag && !FirstInvalidFragment)
|
if (RelaxedFrag && !FirstRelaxedFragment)
|
||||||
FirstInvalidFragment = I;
|
FirstRelaxedFragment = I;
|
||||||
}
|
}
|
||||||
if (FirstInvalidFragment) {
|
if (FirstRelaxedFragment) {
|
||||||
Layout.invalidateFragmentsAfter(FirstInvalidFragment);
|
Layout.invalidateFragmentsAfter(FirstRelaxedFragment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user