skan created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. skan edited the summary of this revision.
The option `-mpad-max-prefix-size` performs some checking and delegate to MC option `-x86-pad-max-prefix-size`. This option is designed for eliminate NOPs when we need to align something by adding redundant prefixes to instructions, e.g. it can be used along with `-malign-branch`, `-malign-branch-boundary` to prefix padding branch. It has similar (but slightly different) effect as GAS's option `-malign-branch-prefix-size`, e.g. `-mpad-max-prefix-size` can also elminate NOPs emitted by align directive, so we use a different name here. I remove the option `-malign-branch-prefix-size` since is unimplemented and not needed. If we need to be compatible with GAS, we can make `-malign-branch-prefix-size` an alias for this option later. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D77628 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/x86-malign-branch.c clang/test/Driver/x86-malign-branch.s Index: clang/test/Driver/x86-malign-branch.s =================================================================== --- clang/test/Driver/x86-malign-branch.s +++ clang/test/Driver/x86-malign-branch.s @@ -6,8 +6,8 @@ // RUN: %clang -target x86_64 -malign-branch=fused,jcc,jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE // TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX -// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5" +// RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX +// PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5" // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B // 32B: "-mllvm" "-x86-branches-within-32B-boundaries" Index: clang/test/Driver/x86-malign-branch.c =================================================================== --- clang/test/Driver/x86-malign-branch.c +++ clang/test/Driver/x86-malign-branch.c @@ -18,13 +18,13 @@ // TYPE-ERR: invalid argument 'foo' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect // TYPE-ERR: invalid argument 'bar' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect -/// Test -malign-branch-prefix-size= -// RUN: %clang -target x86_64 -malign-branch-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0 -// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5 -// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5" +/// Test -mpad-max-prefix-size= +// RUN: %clang -target x86_64 -mpad-max-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0 +// PREFIX-0: "-mllvm" "-x86-pad-max-prefix-size=0" +// RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5 +// PREFIX-5: "-mllvm" "-x86-pad-max-prefix-size=5" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6 +// RUN: %clang -target x86_64 -mpad-max-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6 // PREFIX-6: invalid argument /// Test -mbranches-within-32B-boundaries @@ -34,6 +34,6 @@ /// Unsupported on other targets. // RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s -// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s +// RUN: %clang -target aarch64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // RUN: %clang -target aarch64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // UNUSED: warning: argument unused Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2079,7 +2079,7 @@ CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + AlignBranch)); } if (const Arg *A = - Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) { + Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) { StringRef Value = A->getValue(); unsigned PrefixSize; if (Value.getAsInteger(10, PrefixSize) || PrefixSize > 5) { @@ -2087,7 +2087,7 @@ << Value << A->getOption().getName(); } else { CmdArgs.push_back("-mllvm"); - CmdArgs.push_back(Args.MakeArgString("-x86-align-branch-prefix-size=" + + CmdArgs.push_back(Args.MakeArgString("-x86-pad-max-prefix-size=" + Twine(PrefixSize))); } } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2187,7 +2187,8 @@ HelpText<"Specify types of branches to align">; def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, Group<m_Group>, Flags<[DriverOption]>, HelpText<"Specify the boundary's size to align branches">; -def malign_branch_prefix_size_EQ : Joined<["-"], "malign-branch-prefix-size=">, Group<m_Group>; +def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, Group<m_Group>, Flags<[DriverOption]>, + HelpText<"Specify maximum number of prefixes to use for padding">; def mbranches_within_32B_boundaries : Flag<["-"], "mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group<m_Group>, HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte boundary">; def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, Group<clang_ignored_m_Group>;
Index: clang/test/Driver/x86-malign-branch.s =================================================================== --- clang/test/Driver/x86-malign-branch.s +++ clang/test/Driver/x86-malign-branch.s @@ -6,8 +6,8 @@ // RUN: %clang -target x86_64 -malign-branch=fused,jcc,jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE // TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX -// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5" +// RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX +// PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5" // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B // 32B: "-mllvm" "-x86-branches-within-32B-boundaries" Index: clang/test/Driver/x86-malign-branch.c =================================================================== --- clang/test/Driver/x86-malign-branch.c +++ clang/test/Driver/x86-malign-branch.c @@ -18,13 +18,13 @@ // TYPE-ERR: invalid argument 'foo' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect // TYPE-ERR: invalid argument 'bar' to -malign-branch=; each element must be one of: fused, jcc, jmp, call, ret, indirect -/// Test -malign-branch-prefix-size= -// RUN: %clang -target x86_64 -malign-branch-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0 -// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5 -// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5" +/// Test -mpad-max-prefix-size= +// RUN: %clang -target x86_64 -mpad-max-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0 +// PREFIX-0: "-mllvm" "-x86-pad-max-prefix-size=0" +// RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5 +// PREFIX-5: "-mllvm" "-x86-pad-max-prefix-size=5" -// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6 +// RUN: %clang -target x86_64 -mpad-max-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6 // PREFIX-6: invalid argument /// Test -mbranches-within-32B-boundaries @@ -34,6 +34,6 @@ /// Unsupported on other targets. // RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s -// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s +// RUN: %clang -target aarch64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // RUN: %clang -target aarch64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s // UNUSED: warning: argument unused Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2079,7 +2079,7 @@ CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + AlignBranch)); } if (const Arg *A = - Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) { + Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) { StringRef Value = A->getValue(); unsigned PrefixSize; if (Value.getAsInteger(10, PrefixSize) || PrefixSize > 5) { @@ -2087,7 +2087,7 @@ << Value << A->getOption().getName(); } else { CmdArgs.push_back("-mllvm"); - CmdArgs.push_back(Args.MakeArgString("-x86-align-branch-prefix-size=" + + CmdArgs.push_back(Args.MakeArgString("-x86-pad-max-prefix-size=" + Twine(PrefixSize))); } } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2187,7 +2187,8 @@ HelpText<"Specify types of branches to align">; def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, Group<m_Group>, Flags<[DriverOption]>, HelpText<"Specify the boundary's size to align branches">; -def malign_branch_prefix_size_EQ : Joined<["-"], "malign-branch-prefix-size=">, Group<m_Group>; +def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, Group<m_Group>, Flags<[DriverOption]>, + HelpText<"Specify maximum number of prefixes to use for padding">; def mbranches_within_32B_boundaries : Flag<["-"], "mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group<m_Group>, HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte boundary">; def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, Group<clang_ignored_m_Group>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits