Skip to content

Commit ff8c865

Browse files
authored
[Driver] Allow -fbasic-block-sections for AArch64 ELF (llvm#80916)
Basic block sections "all" doesn't work on AArch64 since branch relaxation may create new basic blocks. However, the other basic block section modes should work out of the box since machine function splitting already uses the basic block sections pass.
1 parent d6c2cbb commit ff8c865

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5972,6 +5972,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59725972
<< A->getAsString(Args) << A->getValue();
59735973
else
59745974
A->render(Args, CmdArgs);
5975+
} else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
5976+
// "all" is not supported on AArch64 since branch relaxation creates new
5977+
// basic blocks for some cross-section branches.
5978+
if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
5979+
D.Diag(diag::err_drv_invalid_value)
5980+
<< A->getAsString(Args) << A->getValue();
5981+
else
5982+
A->render(Args, CmdArgs);
59755983
} else if (Triple.isNVPTX()) {
59765984
// Do not pass the option to the GPU compilation. We still want it enabled
59775985
// for the host-side compilation, so seeing it here is not an error.

clang/test/Driver/fbasic-block-sections.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-ALL %s
33
// RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
44
// RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
5+
// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-NONE %s
6+
// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LIST %s
7+
// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 | FileCheck -check-prefix=CHECK-OPT-LABELS %s
8+
// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-INVALID-VALUE %s
59
// RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
610
// RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all -fbasic-block-sections=none %s -S 2>&1 \
711
// RUN: | FileCheck -check-prefix=CHECK-NOOPT %s

0 commit comments

Comments
 (0)