[llvm] r238150 - Move HasInstructions to MCSection.

Rafael Espindola rafael.espindola at gmail.com
Mon May 25 11:34:27 PDT 2015


Author: rafael
Date: Mon May 25 13:34:26 2015
New Revision: 238150

URL: http://llvm.org/viewvc/llvm-project?rev=238150&view=rev
Log:
Move HasInstructions to MCSection.

Modified:
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/include/llvm/MC/MCObjectStreamer.h
    llvm/trunk/include/llvm/MC/MCSection.h
    llvm/trunk/lib/MC/MCAssembler.cpp
    llvm/trunk/lib/MC/MCELFStreamer.cpp
    llvm/trunk/lib/MC/MCObjectStreamer.cpp
    llvm/trunk/lib/MC/MachObjectWriter.cpp

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Mon May 25 13:34:26 2015
@@ -557,10 +557,6 @@ private:
   //
   // 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
   /// below that number.
   SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
@@ -574,9 +570,6 @@ public:
 
   MCSection &getSection() const { return *Section; }
 
-  bool hasInstructions() const { return HasInstructions; }
-  void setHasInstructions(bool Value) { HasInstructions = Value; }
-
   /// \name Fragment Access
   /// @{
 

Modified: llvm/trunk/include/llvm/MC/MCObjectStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectStreamer.h?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectStreamer.h Mon May 25 13:34:26 2015
@@ -146,9 +146,7 @@ public:
   bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
                               unsigned Size) override;
 
-  bool mayHaveInstructions(MCSection &Sec) const override {
-    return Assembler->getOrCreateSectionData(Sec).hasInstructions();
-  }
+  bool mayHaveInstructions(MCSection &Sec) const override;
 };
 
 } // end namespace llvm

Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Mon May 25 13:34:26 2015
@@ -61,9 +61,12 @@ private:
   /// yet.
   bool BundleGroupBeforeFirstInst = false;
 
+  /// Whether this section has had instructions emitted into it.
+  unsigned HasInstructions : 1;
+
 protected:
   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
-      : Begin(Begin), Variant(V), Kind(K) {}
+      : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
   SectionVariant Variant;
   SectionKind Kind;
 
@@ -105,6 +108,9 @@ public:
     BundleGroupBeforeFirstInst = IsFirst;
   }
 
+  bool hasInstructions() const { return HasInstructions; }
+  void setHasInstructions(bool Value) { HasInstructions = Value; }
+
   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
                                     const MCExpr *Subsection) const = 0;
 

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Mon May 25 13:34:26 2015
@@ -293,7 +293,7 @@ MCEncodedFragmentWithFixups::~MCEncodedF
 MCSectionData::MCSectionData() : Section(nullptr) {}
 
 MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A)
-    : Section(&Section), HasInstructions(false) {
+    : Section(&Section) {
   if (A)
     A->getSectionList().push_back(this);
 }

Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Mon May 25 13:34:26 2015
@@ -137,11 +137,14 @@ void MCELFStreamer::EmitAssemblerFlag(MC
 
 // If bundle aligment is used and there are any instructions in the section, it
 // needs to be aligned to at least the bundle size.
-static void setSectionAlignmentForBundling(
-    const MCAssembler &Assembler, MCSectionData *Section) {
-  if (Assembler.isBundlingEnabled() && Section && Section->hasInstructions() &&
-      Section->getSection().getAlignment() < Assembler.getBundleAlignSize())
-    Section->getSection().setAlignment(Assembler.getBundleAlignSize());
+static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
+                                           MCSectionData *SD) {
+  if (!SD)
+    return;
+  MCSection &Section = SD->getSection();
+  if (Assembler.isBundlingEnabled() && Section.hasInstructions() &&
+      Section.getAlignment() < Assembler.getBundleAlignSize())
+    Section.setAlignment(Assembler.getBundleAlignSize());
 }
 
 void MCELFStreamer::ChangeSection(MCSection *Section,

Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Mon May 25 13:34:26 2015
@@ -230,12 +230,16 @@ void MCObjectStreamer::EmitAssignment(MC
   MCStreamer::EmitAssignment(Symbol, Value);
 }
 
+bool MCObjectStreamer::mayHaveInstructions(MCSection &Sec) const {
+  return Sec.hasInstructions();
+}
+
 void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
                                        const MCSubtargetInfo &STI) {
   MCStreamer::EmitInstruction(Inst, STI);
 
   MCSectionData *SD = getCurrentSectionData();
-  SD->setHasInstructions(true);
+  SD->getSection().setHasInstructions(true);
 
   // Now that a machine instruction has been assembled into this section, make
   // a line entry for any .loc directive that has been seen.

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=238150&r1=238149&r2=238150&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Mon May 25 13:34:26 2015
@@ -225,7 +225,7 @@ void MachObjectWriter::WriteSection(cons
   Write32(FileOffset);
 
   unsigned Flags = Section.getTypeAndAttributes();
-  if (SD.hasInstructions())
+  if (Section.hasInstructions())
     Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
 
   assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!");





More information about the llvm-commits mailing list