llvm-project/clang/test/CodeGenCXX/new-infallible.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

8 lines
316 B
C++
Raw Normal View History

[clang] Add support for optional flag -fnew-infallible to restrict exception propagation The declaration for the global new function in C++ is generated in the compiler front-end. When examining exception propagation, we found that this is the largest root throw site propagator requiring unwind code to be generated for callers up the stack. Allowing this to be handled immediately with termination stops upward propagation and leads to significantly less landing pads generated. This in turns leads to a performance and .text size win. With `-fnew-infallible` this annotates the declaration with `throw()` and `__attribute__((returns_nonnull))`. `throw()` allows the compiler to assume exceptions do not propagate out of new and eliminate it as a root throw site. Note that the definition of global new is user-replaceable so users should ensure that the one used follows these semantics. Measuring internally, we're seeing at 0.5% CPU win in one of our large internal FB workload. Measuring on clang self-build (cd0a1226b50081e86eb75a89d01e8782423971a0) we get: thinlto/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 153494, "dwarfehprepare.NumNoUnwind": 26309, thinlto_newinfallible/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 143660, "dwarfehprepare.NumNoUnwind": 28744, a 1-143660/153494 = 6.4% reduction in landing pads and a 28744/26309 = 9.3% increase in the number of nounwind functions. Testing: ninja check-all new test case to make sure these attributes are added correctly to global new. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D105225
2021-08-03 06:44:10 +08:00
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fnew-infallible -o - %s | FileCheck %s
// CHECK: call noalias noundef nonnull i8* @_Znwm(i64 noundef 4)
[clang] Add support for optional flag -fnew-infallible to restrict exception propagation The declaration for the global new function in C++ is generated in the compiler front-end. When examining exception propagation, we found that this is the largest root throw site propagator requiring unwind code to be generated for callers up the stack. Allowing this to be handled immediately with termination stops upward propagation and leads to significantly less landing pads generated. This in turns leads to a performance and .text size win. With `-fnew-infallible` this annotates the declaration with `throw()` and `__attribute__((returns_nonnull))`. `throw()` allows the compiler to assume exceptions do not propagate out of new and eliminate it as a root throw site. Note that the definition of global new is user-replaceable so users should ensure that the one used follows these semantics. Measuring internally, we're seeing at 0.5% CPU win in one of our large internal FB workload. Measuring on clang self-build (cd0a1226b50081e86eb75a89d01e8782423971a0) we get: thinlto/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 153494, "dwarfehprepare.NumNoUnwind": 26309, thinlto_newinfallible/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 143660, "dwarfehprepare.NumNoUnwind": 28744, a 1-143660/153494 = 6.4% reduction in landing pads and a 28744/26309 = 9.3% increase in the number of nounwind functions. Testing: ninja check-all new test case to make sure these attributes are added correctly to global new. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D105225
2021-08-03 06:44:10 +08:00
// CHECK: ; Function Attrs: nobuiltin nounwind allocsize(0)
// CHECK-NEXT: declare noundef nonnull i8* @_Znwm(i64 noundef)
[clang] Add support for optional flag -fnew-infallible to restrict exception propagation The declaration for the global new function in C++ is generated in the compiler front-end. When examining exception propagation, we found that this is the largest root throw site propagator requiring unwind code to be generated for callers up the stack. Allowing this to be handled immediately with termination stops upward propagation and leads to significantly less landing pads generated. This in turns leads to a performance and .text size win. With `-fnew-infallible` this annotates the declaration with `throw()` and `__attribute__((returns_nonnull))`. `throw()` allows the compiler to assume exceptions do not propagate out of new and eliminate it as a root throw site. Note that the definition of global new is user-replaceable so users should ensure that the one used follows these semantics. Measuring internally, we're seeing at 0.5% CPU win in one of our large internal FB workload. Measuring on clang self-build (cd0a1226b50081e86eb75a89d01e8782423971a0) we get: thinlto/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 153494, "dwarfehprepare.NumNoUnwind": 26309, thinlto_newinfallible/ "dwarfehprepare.NumCleanupLandingPadsRemaining": 143660, "dwarfehprepare.NumNoUnwind": 28744, a 1-143660/153494 = 6.4% reduction in landing pads and a 28744/26309 = 9.3% increase in the number of nounwind functions. Testing: ninja check-all new test case to make sure these attributes are added correctly to global new. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D105225
2021-08-03 06:44:10 +08:00
int *new_infallible = new int;