LCOV - code coverage report
Current view: top level - lib/MC - MCSection.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 28 92.9 %
Date: 2018-06-17 00:07:59 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/MC/MCSection.h"
      11             : #include "llvm/ADT/SmallVector.h"
      12             : #include "llvm/Config/llvm-config.h"
      13             : #include "llvm/MC/MCContext.h"
      14             : #include "llvm/MC/MCFragment.h"
      15             : #include "llvm/MC/MCSymbol.h"
      16             : #include "llvm/Support/Compiler.h"
      17             : #include "llvm/Support/ErrorHandling.h"
      18             : #include "llvm/Support/raw_ostream.h"
      19             : #include <algorithm>
      20             : #include <utility>
      21             : 
      22             : using namespace llvm;
      23             : 
      24     1988951 : MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
      25             :     : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
      26     3977902 :       IsRegistered(false), DummyFragment(this), Variant(V), Kind(K) {}
      27             : 
      28       38863 : MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
      29       38863 :   if (!End)
      30       38785 :     End = Ctx.createTempSymbol("sec_end", true);
      31       38863 :   return End;
      32             : }
      33             : 
      34           0 : bool MCSection::hasEnded() const { return End && End->isInSection(); }
      35             : 
      36             : MCSection::~MCSection() = default;
      37             : 
      38        1190 : void MCSection::setBundleLockState(BundleLockStateType NewState) {
      39        1190 :   if (NewState == NotBundleLocked) {
      40         593 :     if (BundleLockNestingDepth == 0) {
      41           0 :       report_fatal_error("Mismatched bundle_lock/unlock directives");
      42             :     }
      43         593 :     if (--BundleLockNestingDepth == 0) {
      44         585 :       BundleLockState = NotBundleLocked;
      45             :     }
      46             :     return;
      47             :   }
      48             : 
      49             :   // If any of the directives is an align_to_end directive, the whole nested
      50             :   // group is align_to_end. So don't downgrade from align_to_end to just locked.
      51         597 :   if (BundleLockState != BundleLockedAlignToEnd) {
      52         595 :     BundleLockState = NewState;
      53             :   }
      54         597 :   ++BundleLockNestingDepth;
      55             : }
      56             : 
      57             : MCSection::iterator
      58      550124 : MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
      59      550124 :   if (Subsection == 0 && SubsectionFragmentMap.empty())
      60             :     return end();
      61             : 
      62             :   SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI =
      63             :       std::lower_bound(SubsectionFragmentMap.begin(),
      64             :                        SubsectionFragmentMap.end(),
      65             :                        std::make_pair(Subsection, (MCFragment *)nullptr));
      66             :   bool ExactMatch = false;
      67           8 :   if (MI != SubsectionFragmentMap.end()) {
      68           4 :     ExactMatch = MI->first == Subsection;
      69           4 :     if (ExactMatch)
      70           1 :       ++MI;
      71             :   }
      72             :   iterator IP;
      73           8 :   if (MI == SubsectionFragmentMap.end())
      74             :     IP = end();
      75             :   else
      76           4 :     IP = MI->second->getIterator();
      77           8 :   if (!ExactMatch && Subsection != 0) {
      78             :     // The GNU as documentation claims that subsections have an alignment of 4,
      79             :     // although this appears not to be the case.
      80           5 :     MCFragment *F = new MCDataFragment();
      81           5 :     SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
      82             :     getFragmentList().insert(IP, F);
      83             :     F->setParent(this);
      84             :   }
      85             : 
      86           8 :   return IP;
      87             : }
      88             : 
      89             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
      90             : LLVM_DUMP_METHOD void MCSection::dump() const {
      91             :   raw_ostream &OS = errs();
      92             : 
      93             :   OS << "<MCSection";
      94             :   OS << " Fragments:[\n      ";
      95             :   for (auto it = begin(), ie = end(); it != ie; ++it) {
      96             :     if (it != begin())
      97             :       OS << ",\n      ";
      98             :     it->dump();
      99             :   }
     100             :   OS << "]>";
     101             : }
     102             : #endif

Generated by: LCOV version 1.13