diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2024-08-02 02:10:31 +0800 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2024-08-18 15:37:56 -0700 |
commit | c6e16a49ef41261b01aabc27f4b806af6cc81a20 (patch) | |
tree | 563c8ef2a4e98c87f1ccd573557418e284424e59 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | 70f3863b5f30e856278f399b068a30bc4d5d16c2 (diff) | |
download | llvm-c6e16a49ef41261b01aabc27f4b806af6cc81a20.zip llvm-c6e16a49ef41261b01aabc27f4b806af6cc81a20.tar.gz llvm-c6e16a49ef41261b01aabc27f4b806af6cc81a20.tar.bz2 |
[TLI] Add support for inferring attr `cold`/`noreturn` on `std::terminate` and `__cxa_throw`
These functions are both inherently on the error path so `cold` seems
appropriate. `noreturn` is definitional.
Closes #101622
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index c23d53f..b0da198 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -50,6 +50,7 @@ STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns"); STATISTIC(NumReturnedArg, "Number of arguments inferred as returned"); STATISTIC(NumWillReturn, "Number of functions inferred as willreturn"); STATISTIC(NumCold, "Number of functions inferred as cold"); +STATISTIC(NumNoReturn, "Number of functions inferred as no return"); static bool setDoesNotAccessMemory(Function &F) { if (F.doesNotAccessMemory()) @@ -67,6 +68,14 @@ static bool setIsCold(Function &F) { return true; } +static bool setNoReturn(Function &F) { + if (F.hasFnAttribute(Attribute::NoReturn)) + return false; + F.addFnAttr(Attribute::NoReturn); + ++NumNoReturn; + return true; +} + static bool setOnlyAccessesInaccessibleMemory(Function &F) { if (F.onlyAccessesInaccessibleMemory()) return false; @@ -1103,6 +1112,15 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, case LibFunc_abort: Changed |= setIsCold(F); break; + case LibFunc_terminate: + Changed |= setIsCold(F); + Changed |= setNoReturn(F); + break; + case LibFunc_cxa_throw: + Changed |= setIsCold(F); + Changed |= setNoReturn(F); + // Don't add `nofree` on `__cxa_throw` + return Changed; // int __nvvm_reflect(const char *) case LibFunc_nvvm_reflect: Changed |= setRetAndArgsNoUndef(F); |