[PATCH] [MC] When using bundle aligment, align sections to bundle size
Derek Schuff
dschuff at google.com
Mon Apr 20 17:12:04 PDT 2015
- add comments and tighten test
http://reviews.llvm.org/D9131
Files:
lib/MC/MCELFStreamer.cpp
test/MC/X86/AlignedBundling/section-alignment.s
Index: lib/MC/MCELFStreamer.cpp
===================================================================
--- lib/MC/MCELFStreamer.cpp
+++ lib/MC/MCELFStreamer.cpp
@@ -131,13 +131,25 @@
llvm_unreachable("invalid assembler flag!");
}
+// If bundle aligment is used and there are any instructions in the section, it
+// needs to be aligned to at least the bundle size.
+static void setSectionAlignmentForBundling(
+ const MCAssembler &Assembler, MCSectionData *Section) {
+ if (Assembler.isBundlingEnabled() && Section &&
+ Section->hasInstructions() &&
+ Section->getAlignment() < Assembler.getBundleAlignSize())
+ Section->setAlignment(Assembler.getBundleAlignSize());
+}
+
void MCELFStreamer::ChangeSection(const MCSection *Section,
const MCExpr *Subsection) {
MCSectionData *CurSection = getCurrentSectionData();
if (CurSection && CurSection->isBundleLocked())
report_fatal_error("Unterminated .bundle_lock when changing a section");
MCAssembler &Asm = getAssembler();
+ // Ensure the previous section gets aligned if necessary.
+ setSectionAlignmentForBundling(Asm, CurSection);
auto *SectionELF = static_cast<const MCSectionELF *>(Section);
const MCSymbol *Grp = SectionELF->getGroup();
if (Grp)
@@ -639,6 +651,9 @@
}
void MCELFStreamer::FinishImpl() {
+ // Ensure the last section gets aligned if necessary.
+ setSectionAlignmentForBundling(getAssembler(), getCurrentSectionData());
+
EmitFrames(nullptr);
Flush();
Index: test/MC/X86/AlignedBundling/section-alignment.s
===================================================================
--- /dev/null
+++ test/MC/X86/AlignedBundling/section-alignment.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - \
+# RUN: | llvm-readobj -sections | FileCheck %s
+
+# Test that bundle-aligned sections with instructions are aligned
+
+ .bundle_align_mode 5
+# CHECK: Sections
+# Check that the empty .text section has the default alignment
+# CHECK-LABEL: Name: .text
+# CHECK-NOT: Name
+# CHECK: AddressAlignment: 4
+
+ .section text1, "x"
+ imull $17, %ebx, %ebp
+# CHECK-LABEL: Name: text1
+# CHECK: AddressAlignment: 32
+
+ .section text2, "x"
+ imull $17, %ebx, %ebp
+# CHECK-LABEL: Name: text2
+# CHECK: AddressAlignment: 32
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9131.24083.patch
Type: text/x-patch
Size: 2311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150421/b0cfaa5a/attachment.bin>
More information about the llvm-commits
mailing list