[PATCH] D76286: [X86][MC] Support enhanced relaxation for branch align
Kan Shengchen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 19 20:50:52 PDT 2020
skan updated this revision to Diff 251548.
skan added a comment.
[NFC] align the text in the test file
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76286/new/
https://reviews.llvm.org/D76286
Files:
llvm/include/llvm/MC/MCAsmBackend.h
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/test/MC/X86/align-branch-enhanced-relaxation.s
Index: llvm/test/MC/X86/align-branch-enhanced-relaxation.s
===================================================================
--- /dev/null
+++ llvm/test/MC/X86/align-branch-enhanced-relaxation.s
@@ -0,0 +1,38 @@
+ # RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 --x86-align-branch-boundary=32 --x86-align-branch=jmp+indirect | llvm-objdump -d - | FileCheck %s
+
+ # Exercise cases where we are allowed to increase the length of unrelaxable
+ # instructions (by adding prefixes) for alignment purposes.
+
+ # The first test is a basic test, we just check the jmp is aligned by prefix
+ # padding the previous instructions.
+ .text
+ .globl labeled_basic_test
+labeled_basic_test:
+ .p2align 5
+ .rept 30
+ int3
+ .endr
+# CHECK: 1e: 2e cc int3
+# CHECK: 20: eb 00 jmp
+ int3
+ jmp foo
+foo:
+ ret
+
+ # The second test check the correctness cornercase - can't add prefixes on a
+ # prefix or a instruction following by a prefix.
+ .globl labeled_prefix_test
+labeled_prefix_test:
+ .p2align 5
+ .rept 28
+ int3
+ .endr
+# CHECK: 5c: 2e cc int3
+ int3
+# CHECK: 5e: 3e cc int3
+ DS
+ int3
+# CHECK: 60: eb 00 jmp
+ jmp bar
+bar:
+ ret
Index: llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
===================================================================
--- llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -162,6 +162,7 @@
}
bool allowAutoPadding() const override;
+ bool allowEnhancedRelaxation() const override;
void emitInstructionBegin(MCObjectStreamer &OS, const MCInst &Inst) override;
void emitInstructionEnd(MCObjectStreamer &OS, const MCInst &Inst) override;
@@ -455,6 +456,10 @@
return (AlignBoundary != Align(1) && AlignBranchType != X86::AlignBranchNone);
}
+bool X86AsmBackend::allowEnhancedRelaxation() const {
+ return allowAutoPadding() && X86PadMaxPrefixSize != 0 && X86PadForBranchAlign;
+}
+
bool X86AsmBackend::needAlign(MCObjectStreamer &OS) const {
if (!OS.getAllowAutoPadding())
return false;
Index: llvm/lib/MC/MCObjectStreamer.cpp
===================================================================
--- llvm/lib/MC/MCObjectStreamer.cpp
+++ llvm/lib/MC/MCObjectStreamer.cpp
@@ -385,7 +385,9 @@
// If this instruction doesn't need relaxation, just emit it as data.
MCAssembler &Assembler = getAssembler();
- if (!Assembler.getBackend().mayNeedRelaxation(Inst, STI)) {
+ MCAsmBackend &Backend = Assembler.getBackend();
+ if (!(Backend.mayNeedRelaxation(Inst, STI) ||
+ Backend.allowEnhancedRelaxation())) {
EmitInstToData(Inst, STI);
return;
}
Index: llvm/include/llvm/MC/MCAsmBackend.h
===================================================================
--- llvm/include/llvm/MC/MCAsmBackend.h
+++ llvm/include/llvm/MC/MCAsmBackend.h
@@ -49,6 +49,10 @@
/// Return true if this target might automatically pad instructions and thus
/// need to emit padding enable/disable directives around sensative code.
virtual bool allowAutoPadding() const { return false; }
+ /// Return true if this target allows an unrelaxable instruction to be
+ /// emitted into RelaxableFragment and then we can increase its size in a
+ /// tricky way for optimization.
+ virtual bool allowEnhancedRelaxation() const { return false; }
/// Give the target a chance to manipulate state related to instruction
/// alignment (e.g. padding for optimization), instruction relaxablility, etc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76286.251548.patch
Type: text/x-patch
Size: 3679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200320/0363bd41/attachment.bin>
More information about the llvm-commits
mailing list