Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ Modified Compiler Flags
- The `-gkey-instructions` compiler flag is now enabled by default when DWARF is emitted for plain C/C++ and optimizations are enabled. (#GH149509)
- The `-fconstexpr-steps` compiler flag now accepts value `0` to opt out of this limit. (#GH160440)
- The `-mno-outline` and `-moutline` compiler flags are now allowed on RISC-V and X86, which both support the machine outliner.
- The `-mno-outline` flag will now add the `nooutline` IR attribute, so that
`-mno-outline` and `-moutline` objects can be mixed correctly during LTO.

Removed Compiler Flags
-------------------------
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ CODEGENOPT(ResMayAlias, 1, 0, Benign)
ENUM_CODEGENOPT(WinX64EHUnwindV2, WinX64EHUnwindV2Mode,
2, WinX64EHUnwindV2Mode::Disabled, Benign)

/// Adds attributes that prevent outlining (`-mno-outline`)
CODEGENOPT(DisableOutlining, 1, 0, Benign)

/// FIXME: Make DebugOptions its own top-level .def file.
#include "DebugOptions.def"

Expand Down
17 changes: 7 additions & 10 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5127,16 +5127,13 @@ def mms_bitfields : Flag<["-"], "mms-bitfields">, Group<m_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard">,
MarshallingInfoFlag<LangOpts<"MSBitfields">>;
def moutline
: Flag<["-"], "moutline">,
Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Enable function outlining (AArch64,Arm,RISC-V,X86 only)">;
def mno_outline
: Flag<["-"], "mno-outline">,
Group<f_clang_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Disable function outlining (AArch64,Arm,RISC-V,X86 only)">;
defm outline
: BoolMOption<
"outline", CodeGenOpts<"DisableOutlining">, DefaultFalse,
NegFlag<SetTrue, [], [ClangOption, CC1Option],
"Disable function outlining (AArch64,Arm,RISC-V,X86 only)">,
PosFlag<SetFalse, [], [ClangOption],
"Enable function outlining (AArch64,Arm,RISC-V,X86 only)">>;
def mno_ms_bitfields : Flag<["-"], "mno-ms-bitfields">, Group<m_Group>,
HelpText<"Do not set the default structure layout to be compatible with the Microsoft compiler standard">;
def mskip_rax_setup : Flag<["-"], "mskip-rax-setup">, Group<m_Group>,
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2820,7 +2820,9 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
B.addAttribute(llvm::Attribute::MinSize);
}

if (D->hasAttr<NoOutlineAttr>())
// Add `nooutline` if Outlining is disabled with a command-line flag or a
// function attribute.
if (CodeGenOpts.DisableOutlining || D->hasAttr<NoOutlineAttr>())
B.addAttribute(llvm::Attribute::NoOutline);

F->addFnAttrs(B);
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2923,13 +2923,16 @@ void tools::addMachineOutlinerArgs(const Driver &D,
Triple.isRISCV() || Triple.isX86())) {
D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
} else {
// FIXME: This should probably use the `nooutline` attribute rather than
// tweaking Pipeline Pass flags, so `-mno-outline` and `-moutline`
// objects can be combined correctly during LTO.
// Enable Pass in pipeline
addArg(Twine("-enable-machine-outliner"));
}
} else {
// Disable all outlining behaviour.
if (!IsLTO)
// Disable all outlining behaviour using `nooutline` option, in case
// Linker Invocation lacks `-mno-outline`.
CmdArgs.push_back("-mno-outline");

// Disable Pass in Pipeline
addArg(Twine("-enable-machine-outliner=never"));
}
}
Expand Down
17 changes: 14 additions & 3 deletions clang/test/CodeGen/attr-nooutline.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --version 6
// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s --check-prefix=C
// RUN: %clang_cc1 -emit-llvm -x c++ %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s --check-prefix=CXX
// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -DTEST_ATTR -o - | FileCheck %s --check-prefix=C
// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -mno-outline -o - | FileCheck %s --check-prefix=C
// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -mno-outline -DTEST_ATTR -o - | FileCheck %s --check-prefix=C

// RUN: %clang_cc1 -emit-llvm -x c++ %s -triple x86_64-unknown-linux-gnu -DTEST_ATTR -o - | FileCheck %s --check-prefix=CXX
// RUN: %clang_cc1 -emit-llvm -x c++ %s -triple x86_64-unknown-linux-gnu -mno-outline -o - | FileCheck %s --check-prefix=CXX
// RUN: %clang_cc1 -emit-llvm -x c++ %s -triple x86_64-unknown-linux-gnu -mno-outline -DTEST_ATTR -o - | FileCheck %s --check-prefix=CXX

#ifdef TEST_ATTR
#define NOOUTLINE [[clang::nooutline]]
#else
#define NOOUTLINE
#endif

// C: Function Attrs: noinline nooutline nounwind optnone
// C-LABEL: define dso_local i32 @t1(
Expand All @@ -20,6 +31,6 @@
// CXX-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
// CXX-NEXT: ret i32 [[TMP0]]
//
[[clang::nooutline]] int t1(int x) {
NOOUTLINE int t1(int x) {
return x;
}
2 changes: 1 addition & 1 deletion clang/test/Driver/aarch64-outliner.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// ON: "-mllvm" "-enable-machine-outliner"
// RUN: %clang --target=aarch64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// RUN: %clang --target=aarch64_be -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// OFF: "-mno-outline" "-mllvm" "-enable-machine-outliner=never"
2 changes: 1 addition & 1 deletion clang/test/Driver/arm-machine-outliner.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline %s -### 2>&1 | FileCheck %s -check-prefix=ON-LTO
// ON-LTO: "-plugin-opt=-enable-machine-outliner"
// RUN: %clang -target armv7-linux-gnueabihf -moutline -mno-outline -c %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// OFF: "-mno-outline" "-mllvm" "-enable-machine-outliner=never"
// RUN: %clang -target armv7-linux-gnueabihf -flto -moutline -mno-outline %s -### 2>&1 | FileCheck %s -check-prefix=OFF-LTO
// OFF-LTO: "-plugin-opt=-enable-machine-outliner=never"
2 changes: 1 addition & 1 deletion clang/test/Driver/riscv-outliner.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

// RUN: %clang --target=riscv32 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// RUN: %clang --target=riscv64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// OFF: "-mno-outline" "-mllvm" "-enable-machine-outliner=never"
2 changes: 1 addition & 1 deletion clang/test/Driver/x86-outliner.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

// RUN: %clang --target=i386 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// RUN: %clang --target=x86_64 -moutline -mno-outline -S %s -### 2>&1 | FileCheck %s -check-prefix=OFF
// OFF: "-mllvm" "-enable-machine-outliner=never"
// OFF: "-mno-outline" "-mllvm" "-enable-machine-outliner=never"
Loading