From: Daniel Dunbar Date: Thu, 13 May 2010 01:10:26 +0000 (+0000) Subject: MC: Add MCAlignFragment::OnlyAlignAddress bit. This is a bit of magic that says the... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=456b5012704bcece2c8c28783e6efabb7b998616;p=oota-llvm.git MC: Add MCAlignFragment::OnlyAlignAddress bit. This is a bit of magic that says the align fragment shouldn't contribute to the logical section size, it is will be used for cleaning up the code to handle section alignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103690 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index b641b0241d8..8918dbbb3c3 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -258,12 +258,19 @@ class MCAlignFragment : public MCFragment { /// target dependent. bool EmitNops : 1; + /// OnlyAlignAddress - Flag to indicate that this align is only used to adjust + /// the address space size of a section and that it should not be included as + /// part of the section size. This flag can only be used on the last fragment + /// in a section. + bool OnlyAlignAddress : 1; + public: MCAlignFragment(unsigned _Alignment, int64_t _Value, unsigned _ValueSize, unsigned _MaxBytesToEmit, MCSectionData *SD = 0) : MCFragment(FT_Align, SD), Alignment(_Alignment), Value(_Value),ValueSize(_ValueSize), - MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false) {} + MaxBytesToEmit(_MaxBytesToEmit), EmitNops(false), + OnlyAlignAddress(false) {} /// @name Accessors /// @{ @@ -279,6 +286,9 @@ public: bool hasEmitNops() const { return EmitNops; } void setEmitNops(bool Value) { EmitNops = Value; } + bool hasOnlyAlignAddress() const { return OnlyAlignAddress; } + void setOnlyAlignAddress(bool Value) { OnlyAlignAddress = Value; } + /// @} static bool classof(const MCFragment *F) { diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index ced395c5170..8086b3d4aea 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -392,6 +392,9 @@ void MCAssembler::LayoutFragment(MCAsmLayout &Layout, MCFragment &F) { case MCFragment::FT_Align: { MCAlignFragment &AF = cast(F); + assert((!AF.hasOnlyAlignAddress() || !AF.getNextNode()) && + "Invalid OnlyAlignAddress bit, not the last fragment!"); + EffectiveSize = OffsetToAlignment(Address, AF.getAlignment()); if (EffectiveSize > AF.getMaxBytesToEmit()) EffectiveSize = 0; @@ -474,9 +477,18 @@ void MCAssembler::LayoutSection(MCAsmLayout &Layout, MCFragment *F = &SD.getFragmentList().back(); Size = Layout.getFragmentOffset(F) + Layout.getFragmentEffectiveSize(F); } - Layout.setSectionSize(&SD, Size); Layout.setSectionAddressSize(&SD, Size); Layout.setSectionFileSize(&SD, IsVirtual ? 0 : Size); + + // Handle OnlyAlignAddress bit. + if (!SD.getFragmentList().empty()) { + MCAlignFragment *AF = + dyn_cast(&SD.getFragmentList().back()); + if (AF && AF->hasOnlyAlignAddress()) + Size -= Layout.getFragmentEffectiveSize(AF); + } + + Layout.setSectionSize(&SD, Size); } /// WriteFragmentData - Write the \arg F data to the output file. @@ -856,6 +868,10 @@ void MCAlignFragment::dump() { OS << "MCFragment::dump(); + if (hasEmitNops()) + OS << " (emit nops)"; + if (hasOnlyAlignAddress()) + OS << " (only align section)"; OS << "\n "; OS << " Alignment:" << getAlignment() << " Value:" << getValue() << " ValueSize:" << getValueSize()