aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
diff options
context:
space:
mode:
authorAugie Fackler <augie@google.com>2022-03-29 14:27:30 -0400
committerAugie Fackler <augie@google.com>2022-05-31 10:01:17 -0400
commit73f664601c105e5897e12bf9766c2f7e79c92e62 (patch)
tree520928cc337e9004373f399af2b85322ce917595 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp
parent42861faa8e17058f0b4a027bba13ef59a600e051 (diff)
downloadllvm-73f664601c105e5897e12bf9766c2f7e79c92e62.zip
llvm-73f664601c105e5897e12bf9766c2f7e79c92e62.tar.gz
llvm-73f664601c105e5897e12bf9766c2f7e79c92e62.tar.bz2
BuildLibCalls: infer allockind attributes on relevant functions
Differential Revision: https://reviews.llvm.org/D123089
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BuildLibCalls.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 1caddfa..666b276 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -246,6 +246,14 @@ static bool setAllocFamily(Function &F, StringRef Family) {
return true;
}
+static bool setAllocKind(Function &F, AllocFnKind K) {
+ if (F.hasFnAttribute(Attribute::AllocKind))
+ return false;
+ F.addFnAttr(
+ Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
+ return true;
+}
+
bool llvm::inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name,
const TargetLibraryInfo &TLI) {
Function *F = M->getFunction(Name);
@@ -442,12 +450,14 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_aligned_alloc:
Changed |= setAlignedAllocParam(F, 0);
Changed |= setAllocSize(F, 1, None);
+ Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
LLVM_FALLTHROUGH;
case LibFunc_valloc:
case LibFunc_malloc:
case LibFunc_vec_malloc:
Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
: "malloc");
+ Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
Changed |= setAllocSize(F, 0, None);
Changed |= setOnlyAccessesInaccessibleMemory(F);
Changed |= setRetAndArgsNoUndef(F);
@@ -512,6 +522,8 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
return Changed;
case LibFunc_memalign:
Changed |= setAllocFamily(F, "malloc");
+ Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Aligned |
+ AllocFnKind::Uninitialized);
Changed |= setAllocSize(F, 1, None);
Changed |= setAlignedAllocParam(F, 0);
Changed |= setOnlyAccessesInaccessibleMemory(F);
@@ -537,6 +549,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_vec_realloc:
Changed |= setAllocFamily(
F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
+ Changed |= setAllocKind(F, AllocFnKind::Realloc);
Changed |= setAllocatedPointerParam(F, 0);
Changed |= setAllocSize(F, 1, None);
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
@@ -614,6 +627,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_vec_calloc:
Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
: "malloc");
+ Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
Changed |= setAllocSize(F, 0, 1);
Changed |= setOnlyAccessesInaccessibleMemory(F);
Changed |= setRetAndArgsNoUndef(F);
@@ -675,6 +689,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
case LibFunc_vec_free:
Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
: "malloc");
+ Changed |= setAllocKind(F, AllocFnKind::Free);
Changed |= setAllocatedPointerParam(F, 0);
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
Changed |= setArgsNoUndef(F);