mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-03 09:14:30 +00:00
MC: Track section layout order explicitly, and use to simplify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103616 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
62d50e89e4
commit
bc1a0cf139
@ -10,6 +10,8 @@
|
|||||||
#ifndef LLVM_MC_MCASMLAYOUT_H
|
#ifndef LLVM_MC_MCASMLAYOUT_H
|
||||||
#define LLVM_MC_MCASMLAYOUT_H
|
#define LLVM_MC_MCASMLAYOUT_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCAssembler;
|
class MCAssembler;
|
||||||
class MCFragment;
|
class MCFragment;
|
||||||
@ -24,11 +26,18 @@ class MCSymbolData;
|
|||||||
/// efficiently compute the exact addresses of any symbol in the assembly file,
|
/// efficiently compute the exact addresses of any symbol in the assembly file,
|
||||||
/// even during the relaxation process.
|
/// even during the relaxation process.
|
||||||
class MCAsmLayout {
|
class MCAsmLayout {
|
||||||
|
public:
|
||||||
|
typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
|
||||||
|
typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MCAssembler &Assembler;
|
MCAssembler &Assembler;
|
||||||
|
|
||||||
|
/// List of sections in layout order.
|
||||||
|
llvm::SmallVector<MCSectionData*, 16> SectionOrder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCAsmLayout(MCAssembler &_Assembler) : Assembler(_Assembler) {}
|
MCAsmLayout(MCAssembler &_Assembler);
|
||||||
|
|
||||||
/// Get the assembler object this is a layout for.
|
/// Get the assembler object this is a layout for.
|
||||||
MCAssembler &getAssembler() const { return Assembler; }
|
MCAssembler &getAssembler() const { return Assembler; }
|
||||||
@ -38,6 +47,16 @@ public:
|
|||||||
/// the delta from the old size.
|
/// the delta from the old size.
|
||||||
void UpdateForSlide(MCFragment *F, int SlideAmount);
|
void UpdateForSlide(MCFragment *F, int SlideAmount);
|
||||||
|
|
||||||
|
/// @name Section Access (in layout order)
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
iterator begin() { return SectionOrder.begin(); }
|
||||||
|
const_iterator begin() const { return SectionOrder.begin(); }
|
||||||
|
|
||||||
|
iterator end() {return SectionOrder.end();}
|
||||||
|
const_iterator end() const {return SectionOrder.end();}
|
||||||
|
|
||||||
|
/// @}
|
||||||
/// @name Fragment Layout Data
|
/// @name Fragment Layout Data
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -47,6 +47,16 @@ STATISTIC(SectionLayouts, "Number of section layouts");
|
|||||||
|
|
||||||
/* *** */
|
/* *** */
|
||||||
|
|
||||||
|
MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) {
|
||||||
|
// Compute the section layout order. Virtual sections must go last.
|
||||||
|
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||||
|
if (!Asm.getBackend().isVirtualSection(it->getSection()))
|
||||||
|
SectionOrder.push_back(&*it);
|
||||||
|
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||||
|
if (Asm.getBackend().isVirtualSection(it->getSection()))
|
||||||
|
SectionOrder.push_back(&*it);
|
||||||
|
}
|
||||||
|
|
||||||
void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) {
|
void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) {
|
||||||
// We shouldn't have to do anything special to support negative slides, and it
|
// We shouldn't have to do anything special to support negative slides, and it
|
||||||
// is a perfectly valid thing to do as long as other parts of the system can
|
// is a perfectly valid thing to do as long as other parts of the system can
|
||||||
@ -59,24 +69,10 @@ void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) {
|
|||||||
// FIXME-PERF: This is O(N^2), but will be eliminated once we get smarter.
|
// FIXME-PERF: This is O(N^2), but will be eliminated once we get smarter.
|
||||||
|
|
||||||
// Layout the concrete sections and fragments.
|
// Layout the concrete sections and fragments.
|
||||||
MCAssembler &Asm = getAssembler();
|
|
||||||
uint64_t Address = 0;
|
uint64_t Address = 0;
|
||||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it) {
|
for (iterator it = begin(), ie = end(); it != ie; ++it) {
|
||||||
// Skip virtual sections.
|
|
||||||
if (Asm.getBackend().isVirtualSection(it->getSection()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Layout the section fragments and its size.
|
// Layout the section fragments and its size.
|
||||||
Address = Asm.LayoutSection(*it, *this, Address);
|
Address = getAssembler().LayoutSection(**it, *this, Address);
|
||||||
}
|
|
||||||
|
|
||||||
// Layout the virtual sections.
|
|
||||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it) {
|
|
||||||
if (!Asm.getBackend().isVirtualSection(it->getSection()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Layout the section fragments and its size.
|
|
||||||
Address = Asm.LayoutSection(*it, *this, Address);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,22 +707,10 @@ bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
|
|||||||
|
|
||||||
// Layout the concrete sections and fragments.
|
// Layout the concrete sections and fragments.
|
||||||
uint64_t Address = 0;
|
uint64_t Address = 0;
|
||||||
for (iterator it = begin(), ie = end(); it != ie; ++it) {
|
for (MCAsmLayout::iterator it = Layout.begin(),
|
||||||
// Skip virtual sections.
|
ie = Layout.end(); it != ie; ++it) {
|
||||||
if (getBackend().isVirtualSection(it->getSection()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Layout the section fragments and its size.
|
// Layout the section fragments and its size.
|
||||||
Address = LayoutSection(*it, Layout, Address);
|
Address = LayoutSection(**it, Layout, Address);
|
||||||
}
|
|
||||||
|
|
||||||
// Layout the virtual sections.
|
|
||||||
for (iterator it = begin(), ie = end(); it != ie; ++it) {
|
|
||||||
if (!getBackend().isVirtualSection(it->getSection()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Layout the section fragments and its size.
|
|
||||||
Address = LayoutSection(*it, Layout, Address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan for fragments that need relaxation.
|
// Scan for fragments that need relaxation.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user