Move HasInstructions to MCSection.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 May 2015 18:34:26 +0000 (18:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 May 2015 18:34:26 +0000 (18:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238150 91177308-0d34-0410-b5e6-96231b3b80d8

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

index da3fb9f2fafb57dfbba2cc8165f475da2d68084d..ee7583e0e8286e72c69a457fbd7136d3d8c0657b 100644 (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
   /// below that number.
   SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
   /// 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; }
 
 
   MCSection &getSection() const { return *Section; }
 
-  bool hasInstructions() const { return HasInstructions; }
-  void setHasInstructions(bool Value) { HasInstructions = Value; }
-
   /// \name Fragment Access
   /// @{
 
   /// \name Fragment Access
   /// @{
 
index 284dd55443d52de6d7247f34b9244a5cbb364059..646603975f54702163463f30044994ef4d8ed6ed 100644 (file)
@@ -146,9 +146,7 @@ public:
   bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
                               unsigned Size) override;
 
   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
 };
 
 } // end namespace llvm
index 99d11c40c4efcdae107b7ed43f8304bdf42a0b0f..4dbf4ba6f02565a40bc99712ea061c0ef99ab4d8 100644 (file)
@@ -61,9 +61,12 @@ private:
   /// yet.
   bool BundleGroupBeforeFirstInst = false;
 
   /// yet.
   bool BundleGroupBeforeFirstInst = false;
 
+  /// Whether this section has had instructions emitted into it.
+  unsigned HasInstructions : 1;
+
 protected:
   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
 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;
 
   SectionVariant Variant;
   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,
                                     const MCExpr *Subsection) const = 0;
 
   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
                                     const MCExpr *Subsection) const = 0;
 
index a3c7c70321c322dfd4c6ba3299077fd8f2062429..d7712f7fc9888de6ed777ba14508cb6d209626cf 100644 (file)
@@ -293,7 +293,7 @@ MCEncodedFragmentWithFixups::~MCEncodedFragmentWithFixups() {
 MCSectionData::MCSectionData() : Section(nullptr) {}
 
 MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A)
 MCSectionData::MCSectionData() : Section(nullptr) {}
 
 MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A)
-    : Section(&Section), HasInstructions(false) {
+    : Section(&Section) {
   if (A)
     A->getSectionList().push_back(this);
 }
   if (A)
     A->getSectionList().push_back(this);
 }
index 0e4d637c8ce2d503c39f596aab86499511c62d7a..23546cc085db30945a6b0d8c1fe4a8e1a043cffd 100644 (file)
@@ -137,11 +137,14 @@ void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
 
 // If bundle aligment is used and there are any instructions in the section, it
 // needs to be aligned to at least the bundle size.
 
 // 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,
 }
 
 void MCELFStreamer::ChangeSection(MCSection *Section,
index b244c3a679c1995dd0686f9f67a8cbd4f961b6cd..8584a79a8d13fcd6830fb58dd918ec85167c1df8 100644 (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,
                                        const MCSubtargetInfo &STI) {
   MCStreamer::EmitInstruction(Inst, STI);
 
   MCSectionData *SD = getCurrentSectionData();
 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.
 
   // Now that a machine instruction has been assembled into this section, make
   // a line entry for any .loc directive that has been seen.
index 45096d428b76062ffbe00ff4ee87d6db081855c7..79de0f9a9362937f7075b71787525f1bdbe00958 100644 (file)
@@ -225,7 +225,7 @@ void MachObjectWriter::WriteSection(const MCAssembler &Asm,
   Write32(FileOffset);
 
   unsigned Flags = Section.getTypeAndAttributes();
   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!");
     Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
 
   assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!");