[llvm-commits] [llvm] r97158 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/MachO/Darwin/optimal_nop.s
Kevin Enderby
enderby at apple.com
Thu Feb 25 10:46:04 PST 2010
Author: enderby
Date: Thu Feb 25 12:46:04 2010
New Revision: 97158
URL: http://llvm.org/viewvc/llvm-project?rev=97158&view=rev
Log:
This is a patch to the assembler frontend to detect when aligning a text
section with TextAlignFillValue and calls EmitCodeAlignment() instead of
calling EmitValueToAlignment(). This allows x86 assembly code to be aligned
with optimal nops.
Added:
llvm/trunk/test/MC/MachO/Darwin/optimal_nop.s
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=97158&r1=97157&r2=97158&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Feb 25 12:46:04 2010
@@ -146,7 +146,7 @@
// FIXME: Target hook & command line option for initial section.
Out.SwitchSection(getMachOSection("__TEXT", "__text",
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
- 0, SectionKind()));
+ 0, SectionKind::getText()));
// Prime the lexer.
@@ -1237,8 +1237,14 @@
}
}
- // FIXME: Target specific behavior about how the "extra" bytes are filled.
- Out.EmitValueToAlignment(Alignment, FillExpr, ValueSize, MaxBytesToFill);
+ // FIXME: hard code the parser to use EmitCodeAlignment for text when using
+ // the TextAlignFillValue.
+ if(Out.getCurrentSection()->getKind().isText() &&
+ Lexer.getMAI().getTextAlignFillValue() == FillExpr)
+ Out.EmitCodeAlignment(Alignment, MaxBytesToFill);
+ else
+ // FIXME: Target specific behavior about how the "extra" bytes are filled.
+ Out.EmitValueToAlignment(Alignment, FillExpr, ValueSize, MaxBytesToFill);
return false;
}
Added: llvm/trunk/test/MC/MachO/Darwin/optimal_nop.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/Darwin/optimal_nop.s?rev=97158&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/Darwin/optimal_nop.s (added)
+++ llvm/trunk/test/MC/MachO/Darwin/optimal_nop.s Thu Feb 25 12:46:04 2010
@@ -0,0 +1,156 @@
+// Validate that we can assemble this file exactly like the platform
+// assembler.
+//
+// RUN: llvm-mc -filetype=obj -triple i386-apple-darwin10 -o %t.mc.o %s
+// RUN: as -arch i386 -o %t.as.o %s
+// RUN: diff %t.mc.o %t.as.o
+
+# 1 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ # nop
+ # 0x90
+ .align 1, 0x90
+ ret
+# 2 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ # xchg %ax,%ax
+ # 0x66, 0x90
+ .align 2, 0x90
+ ret
+# 3 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ # nopl (%[re]ax)
+ # 0x0f, 0x1f, 0x00
+ .align 2, 0x90
+ ret
+# 4 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ # nopl 0(%[re]ax)
+ # 0x0f, 0x1f, 0x40, 0x00
+ .align 3, 0x90
+ ret
+# 5 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ # nopl 0(%[re]ax,%[re]ax,1)
+ # 0x0f, 0x1f, 0x44, 0x00, 0x00
+ .align 3, 0x90
+ ret
+# 6 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ # nopw 0(%[re]ax,%[re]ax,1)
+ # 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00
+ .align 3, 0x90
+ ret
+# 7 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ # nopl 0L(%[re]ax)
+ # 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
+ .align 3, 0x90
+ ret
+# 8 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ # nopl 0L(%[re]ax,%[re]ax,1)
+ # 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
+ .align 3, 0x90
+ ret
+# 9 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ # nopw 0L(%[re]ax,%[re]ax,1)
+ # 0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 10 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ ret
+ # nopw %cs:0L(%[re]ax,%[re]ax,1)
+ # 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 11 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ ret
+ # nopw %cs:0L(%[re]ax,%[re]ax,1)
+ # 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 12 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ ret
+ # nopw 0(%[re]ax,%[re]ax,1)
+ # nopw 0(%[re]ax,%[re]ax,1)
+ # 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
+ # 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 13 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ ret
+ # nopw 0(%[re]ax,%[re]ax,1)
+ # nopl 0L(%[re]ax)
+ # 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
+ # 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 14 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ ret
+ # nopl 0L(%[re]ax)
+ # nopl 0L(%[re]ax)
+ # 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
+ # 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
+# 15 byte nop test
+ .align 4, 0 # start with 16 byte alignment filled with zeros
+ ret
+ # nopl 0L(%[re]ax)
+ # nopl 0L(%[re]ax,%[re]ax,1)
+ # 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
+ # 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
+ .align 4, 0x90
+ ret
More information about the llvm-commits
mailing list