Move HasInstructions to MCSection.

llvm-svn: 238150
This commit is contained in:
Rafael Espindola 2015-05-25 18:34:26 +00:00
parent 9bb9f0f392
commit e59724b6cc
7 changed files with 23 additions and 19 deletions

View File

@ -557,10 +557,6 @@ private:
// //
// FIXME: This could all be kept private to the assembler implementation. // FIXME: This could all be kept private to the assembler implementation.
/// HasInstructions - Whether this section has had instructions emitted into
/// it.
unsigned HasInstructions : 1;
/// Mapping from subsection number to insertion point for subsection numbers /// Mapping from subsection number to insertion point for subsection numbers
/// below that number. /// below that number.
SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap; SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
@ -574,9 +570,6 @@ public:
MCSection &getSection() const { return *Section; } MCSection &getSection() const { return *Section; }
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }
/// \name Fragment Access /// \name Fragment Access
/// @{ /// @{

View File

@ -146,9 +146,7 @@ public:
bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
unsigned Size) override; unsigned Size) override;
bool mayHaveInstructions(MCSection &Sec) const override { bool mayHaveInstructions(MCSection &Sec) const override;
return Assembler->getOrCreateSectionData(Sec).hasInstructions();
}
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -61,9 +61,12 @@ private:
/// yet. /// yet.
bool BundleGroupBeforeFirstInst = false; bool BundleGroupBeforeFirstInst = false;
/// Whether this section has had instructions emitted into it.
unsigned HasInstructions : 1;
protected: protected:
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin) MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
: Begin(Begin), Variant(V), Kind(K) {} : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
SectionVariant Variant; SectionVariant Variant;
SectionKind Kind; SectionKind Kind;
@ -105,6 +108,9 @@ public:
BundleGroupBeforeFirstInst = IsFirst; BundleGroupBeforeFirstInst = IsFirst;
} }
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
const MCExpr *Subsection) const = 0; const MCExpr *Subsection) const = 0;

View File

@ -293,7 +293,7 @@ MCEncodedFragmentWithFixups::~MCEncodedFragmentWithFixups() {
MCSectionData::MCSectionData() : Section(nullptr) {} MCSectionData::MCSectionData() : Section(nullptr) {}
MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A) MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A)
: Section(&Section), HasInstructions(false) { : Section(&Section) {
if (A) if (A)
A->getSectionList().push_back(this); A->getSectionList().push_back(this);
} }

View File

@ -137,11 +137,14 @@ void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
// If bundle aligment is used and there are any instructions in the section, it // If bundle aligment is used and there are any instructions in the section, it
// needs to be aligned to at least the bundle size. // needs to be aligned to at least the bundle size.
static void setSectionAlignmentForBundling( static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
const MCAssembler &Assembler, MCSectionData *Section) { MCSectionData *SD) {
if (Assembler.isBundlingEnabled() && Section && Section->hasInstructions() && if (!SD)
Section->getSection().getAlignment() < Assembler.getBundleAlignSize()) return;
Section->getSection().setAlignment(Assembler.getBundleAlignSize()); MCSection &Section = SD->getSection();
if (Assembler.isBundlingEnabled() && Section.hasInstructions() &&
Section.getAlignment() < Assembler.getBundleAlignSize())
Section.setAlignment(Assembler.getBundleAlignSize());
} }
void MCELFStreamer::ChangeSection(MCSection *Section, void MCELFStreamer::ChangeSection(MCSection *Section,

View File

@ -230,12 +230,16 @@ void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
MCStreamer::EmitAssignment(Symbol, Value); MCStreamer::EmitAssignment(Symbol, Value);
} }
bool MCObjectStreamer::mayHaveInstructions(MCSection &Sec) const {
return Sec.hasInstructions();
}
void MCObjectStreamer::EmitInstruction(const MCInst &Inst, void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
const MCSubtargetInfo &STI) { const MCSubtargetInfo &STI) {
MCStreamer::EmitInstruction(Inst, STI); MCStreamer::EmitInstruction(Inst, STI);
MCSectionData *SD = getCurrentSectionData(); MCSectionData *SD = getCurrentSectionData();
SD->setHasInstructions(true); SD->getSection().setHasInstructions(true);
// Now that a machine instruction has been assembled into this section, make // Now that a machine instruction has been assembled into this section, make
// a line entry for any .loc directive that has been seen. // a line entry for any .loc directive that has been seen.

View File

@ -225,7 +225,7 @@ void MachObjectWriter::WriteSection(const MCAssembler &Asm,
Write32(FileOffset); Write32(FileOffset);
unsigned Flags = Section.getTypeAndAttributes(); unsigned Flags = Section.getTypeAndAttributes();
if (SD.hasInstructions()) if (Section.hasInstructions())
Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS; Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!"); assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!");