mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-01 16:31:13 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97158 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
55c8a7e778
commit
d74acb0c78
@ -146,7 +146,7 @@ bool AsmParser::Run() {
|
||||
// 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 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
156
test/MC/MachO/Darwin/optimal_nop.s
Normal file
156
test/MC/MachO/Darwin/optimal_nop.s
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user