llvm.org GIT mirror llvm / 0aaf328
[MC] Align fragments when -mc-relax-all flag is used Summary: Ensure that fragments are bundle aligned when instruction bundling is enabled and the -mc-relax-all flag is set. This is implicitly assumed by the bundle padding implementation but this assumption does not hold when custom alignment is being used. The change was tested by running PNaCl toolchain trybots with -mc-relax-all flag set. Fixes https://code.google.com/p/nativeclient/issues/detail?id=4063 Test Plan: Regression test attached Reviewers: mseaborn Subscribers: jfb, llvm-commits Differential Revision: http://reviews.llvm.org/D10044 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240869 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 4 years ago
3 changed file(s) with 66 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
253253 else { // EndOfFragment > BundleSize
254254 return 2 * BundleSize - EndOfFragment;
255255 }
256 } else if (EndOfFragment > BundleSize)
256 } else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
257257 return BundleSize - OffsetInBundle;
258258 else
259259 return 0;
580580 // size won't include the padding.
581581 //
582582 // When the -mc-relax-all flag is used, we optimize bundling by writting the
583 // bundle padding directly into fragments when the instructions are emitted
584 // inside the streamer.
583 // padding directly into fragments when the instructions are emitted inside
584 // the streamer. When the fragment is larger than the bundle size, we need to
585 // ensure that it's bundle aligned. This means that if we end up with
586 // multiple fragments, we must emit bundle padding between fragments.
585587 //
586 if (Assembler.isBundlingEnabled() && !Assembler.getRelaxAll() &&
587 F->hasInstructions()) {
588 // ".align N" is an example of a directive that introduces multiple
589 // fragments. We could add a special case to handle ".align N" by emitting
590 // within-fragment padding (which would produce less padding when N is less
591 // than the bundle size), but for now we don't.
592 //
593 if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
588594 assert(isa(F) &&
589595 "Only MCEncodedFragment implementations have instructions");
590596 uint64_t FSize = Assembler.computeFragmentSize(*this, *F);
591597
592 if (FSize > Assembler.getBundleAlignSize())
598 if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize())
593599 report_fatal_error("Fragment can't be larger than a bundle size");
594600
595601 uint64_t RequiredBundlePadding = computeBundlePadding(Assembler, F,
0 # RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - \
1 # RUN: | llvm-objdump -disassemble -no-show-raw-insn - \
2 # RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK-OPT %s
3 # RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -mc-relax-all %s -o - \
4 # RUN: | llvm-objdump -disassemble -no-show-raw-insn - \
5 # RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK-RELAX %s
6
7 .text
8 foo:
9 .bundle_align_mode 5
10 push %ebp # 1 byte
11 .align 16
12 .bundle_lock align_to_end
13 # CHECK: 1: nopw %cs:(%eax,%eax)
14 # CHECK: 10: nopw %cs:(%eax,%eax)
15 # CHECK-RELAX: 1f: nop
16 # CHECK-RELAX: 20: nopw %cs:(%eax,%eax)
17 # CHECK-RELAX: 2f: nopw %cs:(%eax,%eax)
18 # CHECK-OPT: 1b: calll -4
19 # CHECK-RELAX: 3b: calll -4
20 calll bar # 5 bytes
21 .bundle_unlock
22 ret # 1 byte
0 # RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu %s -o - \
1 # RUN: | llvm-objdump -disassemble -no-show-raw-insn - \
2 # RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK-OPT %s
3 # RUN: llvm-mc -filetype=obj -triple i686-pc-linux-gnu -mc-relax-all %s -o - \
4 # RUN: | llvm-objdump -disassemble -no-show-raw-insn - \
5 # RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK-RELAX %s
6
7 .text
8 foo:
9 .bundle_align_mode 5
10 push %ebp # 1 byte
11 .align 16
12 # CHECK: 1: nopw %cs:(%eax,%eax)
13 # CHECK-RELAX: 10: nopw %cs:(%eax,%eax)
14 # CHECK-RELAX: 1f: nop
15 # CHECK-OPT: 10: movl $1, (%esp)
16 # CHECK-RELAX: 20: movl $1, (%esp)
17 movl $0x1, (%esp) # 7 bytes
18 movl $0x1, (%esp) # 7 bytes
19 # CHECK-OPT: 1e: nop
20 movl $0x2, 0x1(%esp) # 8 bytes
21 movl $0x2, 0x1(%esp) # 8 bytes
22 # CHECK-RELAX: 3e: nop
23 # CHECK-RELAX: 40: movl $2, 1(%esp)
24 movl $0x2, 0x1(%esp) # 8 bytes
25 movl $0x2, (%esp) # 7 bytes
26 # CHECK-OPT: 3f: nop
27 # CHECK-OPT: 40: movl $3, (%esp)
28 movl $0x3, (%esp) # 7 bytes
29 movl $0x3, (%esp) # 7 bytes
30 ret