Move bundle info from MCSectionData to MCSection.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 May 2015 15:04:26 +0000 (15:04 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 May 2015 15:04:26 +0000 (15:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238143 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ac6864a9e58dd68149c78a0f8abb39632332085c..da3fb9f2fafb57dfbba2cc8165f475da2d68084d 100644 (file)
@@ -548,27 +548,10 @@ public:
   typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
   typedef FragmentListType::reverse_iterator reverse_iterator;
 
   typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
   typedef FragmentListType::reverse_iterator reverse_iterator;
 
-  /// \brief Express the state of bundle locked groups while emitting code.
-  enum BundleLockStateType {
-    NotBundleLocked,
-    BundleLocked,
-    BundleLockedAlignToEnd
-  };
-
 private:
   FragmentListType Fragments;
   MCSection *Section;
 
 private:
   FragmentListType Fragments;
   MCSection *Section;
 
-  /// \brief Keeping track of bundle-locked state.
-  BundleLockStateType BundleLockState;
-
-  /// \brief Current nesting depth of bundle_lock directives.
-  unsigned BundleLockNestingDepth;
-
-  /// \brief We've seen a bundle_lock directive but not its first instruction
-  /// yet.
-  bool BundleGroupBeforeFirstInst;
-
   /// \name Assembler Backend Data
   /// @{
   //
   /// \name Assembler Backend Data
   /// @{
   //
@@ -618,20 +601,6 @@ public:
 
   iterator getSubsectionInsertionPoint(unsigned Subsection);
 
 
   iterator getSubsectionInsertionPoint(unsigned Subsection);
 
-  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
-
-  BundleLockStateType getBundleLockState() const { return BundleLockState; }
-
-  void setBundleLockState(BundleLockStateType NewState);
-
-  bool isBundleGroupBeforeFirstInst() const {
-    return BundleGroupBeforeFirstInst;
-  }
-
-  void setBundleGroupBeforeFirstInst(bool IsFirst) {
-    BundleGroupBeforeFirstInst = IsFirst;
-  }
-
   void dump();
 
   /// @}
   void dump();
 
   /// @}
index 5a60a87242940078c350451eba56564dfc06a2d3..99d11c40c4efcdae107b7ed43f8304bdf42a0b0f 100644 (file)
@@ -31,6 +31,13 @@ class MCSection {
 public:
   enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
 
 public:
   enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
 
+  /// \brief Express the state of bundle locked groups while emitting code.
+  enum BundleLockStateType {
+    NotBundleLocked,
+    BundleLocked,
+    BundleLockedAlignToEnd
+  };
+
 private:
   MCSection(const MCSection &) = delete;
   void operator=(const MCSection &) = delete;
 private:
   MCSection(const MCSection &) = delete;
   void operator=(const MCSection &) = delete;
@@ -44,6 +51,16 @@ private:
   /// The index of this section in the layout order.
   unsigned LayoutOrder;
 
   /// The index of this section in the layout order.
   unsigned LayoutOrder;
 
+  /// \brief Keeping track of bundle-locked state.
+  BundleLockStateType BundleLockState = NotBundleLocked;
+
+  /// \brief Current nesting depth of bundle_lock directives.
+  unsigned BundleLockNestingDepth = 0;
+
+  /// \brief We've seen a bundle_lock directive but not its first instruction
+  /// yet.
+  bool BundleGroupBeforeFirstInst = false;
+
 protected:
   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
       : Begin(Begin), Variant(V), Kind(K) {}
 protected:
   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
       : Begin(Begin), Variant(V), Kind(K) {}
@@ -77,6 +94,17 @@ public:
   unsigned getLayoutOrder() const { return LayoutOrder; }
   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
 
   unsigned getLayoutOrder() const { return LayoutOrder; }
   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
 
+  BundleLockStateType getBundleLockState() const { return BundleLockState; }
+  void setBundleLockState(BundleLockStateType NewState);
+  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
+
+  bool isBundleGroupBeforeFirstInst() const {
+    return BundleGroupBeforeFirstInst;
+  }
+  void setBundleGroupBeforeFirstInst(bool IsFirst) {
+    BundleGroupBeforeFirstInst = IsFirst;
+  }
+
   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 cb11555ab510795cc44ecf50c50de71cda4c1e56..a3c7c70321c322dfd4c6ba3299077fd8f2062429 100644 (file)
@@ -293,9 +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), BundleLockState(NotBundleLocked),
-      BundleLockNestingDepth(0), BundleGroupBeforeFirstInst(false),
-      HasInstructions(false) {
+    : Section(&Section), HasInstructions(false) {
   if (A)
     A->getSectionList().push_back(this);
 }
   if (A)
     A->getSectionList().push_back(this);
 }
@@ -331,25 +329,6 @@ MCSectionData::getSubsectionInsertionPoint(unsigned Subsection) {
   return IP;
 }
 
   return IP;
 }
 
-void MCSectionData::setBundleLockState(BundleLockStateType NewState) {
-  if (NewState == NotBundleLocked) {
-    if (BundleLockNestingDepth == 0) {
-      report_fatal_error("Mismatched bundle_lock/unlock directives");
-    }
-    if (--BundleLockNestingDepth == 0) {
-      BundleLockState = NotBundleLocked;
-    }
-    return;
-  }
-
-  // If any of the directives is an align_to_end directive, the whole nested
-  // group is align_to_end. So don't downgrade from align_to_end to just locked.
-  if (BundleLockState != BundleLockedAlignToEnd) {
-    BundleLockState = NewState;
-  }
-  ++BundleLockNestingDepth;
-}
-
 /* *** */
 
 MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
 /* *** */
 
 MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
index 6a47cc9c1ccca7b5b2a6dae7ff7f2e9606dccf8a..0e4d637c8ce2d503c39f596aab86499511c62d7a 100644 (file)
@@ -39,7 +39,7 @@
 using namespace llvm;
 
 bool MCELFStreamer::isBundleLocked() const {
 using namespace llvm;
 
 bool MCELFStreamer::isBundleLocked() const {
-  return getCurrentSectionData()->isBundleLocked();
+  return getCurrentSectionData()->getSection().isBundleLocked();
 }
 
 MCELFStreamer::~MCELFStreamer() {
 }
 
 MCELFStreamer::~MCELFStreamer() {
@@ -507,6 +507,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst,
 
   if (Assembler.isBundlingEnabled()) {
     MCSectionData *SD = getCurrentSectionData();
 
   if (Assembler.isBundlingEnabled()) {
     MCSectionData *SD = getCurrentSectionData();
+    MCSection &Sec = SD->getSection();
     if (Assembler.getRelaxAll() && isBundleLocked())
       // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
       // the current bundle group.
     if (Assembler.getRelaxAll() && isBundleLocked())
       // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
       // the current bundle group.
@@ -516,7 +517,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst,
       // we create a new temporary fragment which will be later merged into
       // the current fragment.
       DF = new MCDataFragment();
       // we create a new temporary fragment which will be later merged into
       // the current fragment.
       DF = new MCDataFragment();
-    else if (isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
+    else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
       // If we are bundle-locked, we re-use the current fragment.
       // The bundle-locking directive ensures this is a new data fragment.
       DF = cast<MCDataFragment>(getCurrentFragment());
       // If we are bundle-locked, we re-use the current fragment.
       // The bundle-locking directive ensures this is a new data fragment.
       DF = cast<MCDataFragment>(getCurrentFragment());
@@ -532,7 +533,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst,
       DF = new MCDataFragment();
       insert(DF);
     }
       DF = new MCDataFragment();
       insert(DF);
     }
-    if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
+    if (Sec.getBundleLockState() == MCSection::BundleLockedAlignToEnd) {
       // If this fragment is for a group marked "align_to_end", set a flag
       // in the fragment. This can happen after the fragment has already been
       // created if there are nested bundle_align groups and an inner one
       // If this fragment is for a group marked "align_to_end", set a flag
       // in the fragment. This can happen after the fragment has already been
       // created if there are nested bundle_align groups and an inner one
@@ -542,7 +543,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst,
 
     // We're now emitting an instruction in a bundle group, so this flag has
     // to be turned off.
 
     // We're now emitting an instruction in a bundle group, so this flag has
     // to be turned off.
-    SD->setBundleGroupBeforeFirstInst(false);
+    Sec.setBundleGroupBeforeFirstInst(false);
   } else {
     DF = getOrCreateDataFragment();
   }
   } else {
     DF = getOrCreateDataFragment();
   }
@@ -575,6 +576,7 @@ void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
 
 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
   MCSectionData *SD = getCurrentSectionData();
 
 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
   MCSectionData *SD = getCurrentSectionData();
+  MCSection &Sec = SD->getSection();
 
   // Sanity checks
   //
 
   // Sanity checks
   //
@@ -582,7 +584,7 @@ void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
     report_fatal_error(".bundle_lock forbidden when bundling is disabled");
 
   if (!isBundleLocked())
     report_fatal_error(".bundle_lock forbidden when bundling is disabled");
 
   if (!isBundleLocked())
-    SD->setBundleGroupBeforeFirstInst(true);
+    Sec.setBundleGroupBeforeFirstInst(true);
 
   if (getAssembler().getRelaxAll() && !isBundleLocked()) {
     // TODO: drop the lock state and set directly in the fragment
 
   if (getAssembler().getRelaxAll() && !isBundleLocked()) {
     // TODO: drop the lock state and set directly in the fragment
@@ -590,19 +592,20 @@ void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
     BundleGroups.push_back(DF);
   }
 
     BundleGroups.push_back(DF);
   }
 
-  SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd :
-                                      MCSectionData::BundleLocked);
+  Sec.setBundleLockState(AlignToEnd ? MCSection::BundleLockedAlignToEnd
+                                    : MCSection::BundleLocked);
 }
 
 void MCELFStreamer::EmitBundleUnlock() {
   MCSectionData *SD = getCurrentSectionData();
 }
 
 void MCELFStreamer::EmitBundleUnlock() {
   MCSectionData *SD = getCurrentSectionData();
+  MCSection &Sec = SD->getSection();
 
   // Sanity checks
   if (!getAssembler().isBundlingEnabled())
     report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
   else if (!isBundleLocked())
     report_fatal_error(".bundle_unlock without matching lock");
 
   // Sanity checks
   if (!getAssembler().isBundlingEnabled())
     report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
   else if (!isBundleLocked())
     report_fatal_error(".bundle_unlock without matching lock");
-  else if (SD->isBundleGroupBeforeFirstInst())
+  else if (Sec.isBundleGroupBeforeFirstInst())
     report_fatal_error("Empty bundle-locked group is forbidden");
 
   // When the -mc-relax-all flag is used, we emit instructions to fragments
     report_fatal_error("Empty bundle-locked group is forbidden");
 
   // When the -mc-relax-all flag is used, we emit instructions to fragments
@@ -613,7 +616,7 @@ void MCELFStreamer::EmitBundleUnlock() {
     MCDataFragment *DF = BundleGroups.back();
 
     // FIXME: Use BundleGroups to track the lock state instead.
     MCDataFragment *DF = BundleGroups.back();
 
     // FIXME: Use BundleGroups to track the lock state instead.
-    SD->setBundleLockState(MCSectionData::NotBundleLocked);
+    Sec.setBundleLockState(MCSection::NotBundleLocked);
 
     // FIXME: Use more separate fragments for nested groups.
     if (!isBundleLocked()) {
 
     // FIXME: Use more separate fragments for nested groups.
     if (!isBundleLocked()) {
@@ -622,10 +625,10 @@ void MCELFStreamer::EmitBundleUnlock() {
       delete DF;
     }
 
       delete DF;
     }
 
-    if (SD->getBundleLockState() != MCSectionData::BundleLockedAlignToEnd)
+    if (Sec.getBundleLockState() != MCSection::BundleLockedAlignToEnd)
       getOrCreateDataFragment()->setAlignToBundleEnd(false);
   } else
       getOrCreateDataFragment()->setAlignToBundleEnd(false);
   } else
-    SD->setBundleLockState(MCSectionData::NotBundleLocked);
+    Sec.setBundleLockState(MCSection::NotBundleLocked);
 }
 
 void MCELFStreamer::Flush() {
 }
 
 void MCELFStreamer::Flush() {
index 3f32a36194f77c9f3480fbfd173809ae54e9e4de..b244c3a679c1995dd0686f9f67a8cbd4f961b6cd 100644 (file)
@@ -254,7 +254,7 @@ void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
   //   group. We want to emit all such instructions into the same data
   //   fragment.
   if (Assembler.getRelaxAll() ||
   //   group. We want to emit all such instructions into the same data
   //   fragment.
   if (Assembler.getRelaxAll() ||
-      (Assembler.isBundlingEnabled() && SD->isBundleLocked())) {
+      (Assembler.isBundlingEnabled() && SD->getSection().isBundleLocked())) {
     MCInst Relaxed;
     getAssembler().getBackend().relaxInstruction(Inst, Relaxed);
     while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
     MCInst Relaxed;
     getAssembler().getBackend().relaxInstruction(Inst, Relaxed);
     while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
index 7204e6cba1f48f12471e100180cf3e244a880d79..bf25f3cc1636d70e0b9e0e107ef007489d98b1ca 100644 (file)
@@ -29,3 +29,21 @@ bool MCSection::hasEnded() const { return End && End->isInSection(); }
 MCSection::~MCSection() {
 }
 
 MCSection::~MCSection() {
 }
 
+void MCSection::setBundleLockState(BundleLockStateType NewState) {
+  if (NewState == NotBundleLocked) {
+    if (BundleLockNestingDepth == 0) {
+      report_fatal_error("Mismatched bundle_lock/unlock directives");
+    }
+    if (--BundleLockNestingDepth == 0) {
+      BundleLockState = NotBundleLocked;
+    }
+    return;
+  }
+
+  // If any of the directives is an align_to_end directive, the whole nested
+  // group is align_to_end. So don't downgrade from align_to_end to just locked.
+  if (BundleLockState != BundleLockedAlignToEnd) {
+    BundleLockState = NewState;
+  }
+  ++BundleLockNestingDepth;
+}