MCSection.cpp 3.1 KB

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