diff options
author | Antonio Frighetto <me@antoniofrighetto.com> | 2025-03-13 10:29:43 +0100 |
---|---|---|
committer | Antonio Frighetto <me@antoniofrighetto.com> | 2025-03-13 12:59:57 +0100 |
commit | da69147a1619813679cef7ee39ec68cf2c8a2732 (patch) | |
tree | 38607c6a666592f602efcaea20d18c36b05acfbb /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | 1eb5588457c39a924902971b7d883e319a499c17 (diff) | |
download | llvm-da69147a1619813679cef7ee39ec68cf2c8a2732.zip llvm-da69147a1619813679cef7ee39ec68cf2c8a2732.tar.gz llvm-da69147a1619813679cef7ee39ec68cf2c8a2732.tar.bz2 |
[InferAttrs] Refine attributes for a few libc routines
Attributes inference has been improved for a few functions.
Particularly, ldexp and variants, as well as abort, may be
marked as `nounwind`, as they do not propagate any exceptions
to the caller, neither they unwind the stack. Besides, fwrite
and fread first argument should be respectively readonly and
writeonly.
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 7274714..2301be6 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -802,6 +802,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setRetAndArgsNoUndef(F); Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 2); + Changed |= setOnlyWritesMemory(F, 0); break; case LibFunc_fread: case LibFunc_fread_unlocked: @@ -809,6 +810,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); Changed |= setDoesNotCapture(F, 3); + Changed |= setOnlyWritesMemory(F, 0); break; case LibFunc_fwrite: case LibFunc_fwrite_unlocked: @@ -816,7 +818,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); Changed |= setDoesNotCapture(F, 3); - // FIXME: readonly #1? + Changed |= setOnlyReadsMemory(F, 0); break; case LibFunc_fputs: case LibFunc_fputs_unlocked: @@ -1150,6 +1152,8 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, break; case LibFunc_abort: Changed |= setIsCold(F); + Changed |= setNoReturn(F); + Changed |= setDoesNotThrow(F); break; case LibFunc_terminate: Changed |= setIsCold(F); @@ -1166,12 +1170,6 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setDoesNotAccessMemory(F); Changed |= setDoesNotThrow(F); break; - case LibFunc_ldexp: - case LibFunc_ldexpf: - case LibFunc_ldexpl: - Changed |= setOnlyWritesErrnoMemory(F); - Changed |= setWillReturn(F); - break; case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosh: @@ -1228,6 +1226,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, case LibFunc_hypot: case LibFunc_hypotf: case LibFunc_hypotl: + case LibFunc_ldexp: + case LibFunc_ldexpf: + case LibFunc_ldexpl: case LibFunc_log: case LibFunc_log10: case LibFunc_log10f: |