MCSection.cpp 3.3 KB

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