aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2025-06-04 08:35:20 +0100
committerGitHub <noreply@github.com>2025-06-04 09:35:20 +0200
commitc7c79d259025f0e5edf778a46e03aeb6affd7c73 (patch)
treef0066601438f302e6ce007d950fedc84db6ee16b /llvm/lib/IR/Verifier.cpp
parentb3ce9883f32e3b5b16e2b5fa54c3d98e85b66869 (diff)
downloadllvm-c7c79d259025f0e5edf778a46e03aeb6affd7c73.zip
llvm-c7c79d259025f0e5edf778a46e03aeb6affd7c73.tar.gz
llvm-c7c79d259025f0e5edf778a46e03aeb6affd7c73.tar.bz2
[IR][DSE] Support non-malloc functions in malloc+memset->calloc fold (#138299)
Add a `alloc-variant-zeroed` function attribute which can be used to inform folding allocation+memset. This addresses https://github.com/rust-lang/rust/issues/104847, where LLVM does not know how to perform this transformation for non-C languages. Co-authored-by: Jamie <jamie@osec.io>
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index fdb4dda..2d03a7a 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2382,6 +2382,31 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
CheckFailed("'allockind()' can't be both zeroed and uninitialized");
}
+ if (Attribute A = Attrs.getFnAttr("alloc-variant-zeroed"); A.isValid()) {
+ StringRef S = A.getValueAsString();
+ Check(!S.empty(), "'alloc-variant-zeroed' must not be empty");
+ Function *Variant = M.getFunction(S);
+ if (Variant) {
+ Attribute Family = Attrs.getFnAttr("alloc-family");
+ Attribute VariantFamily = Variant->getFnAttribute("alloc-family");
+ if (Family.isValid())
+ Check(VariantFamily.isValid() &&
+ VariantFamily.getValueAsString() == Family.getValueAsString(),
+ "'alloc-variant-zeroed' must name a function belonging to the "
+ "same 'alloc-family'");
+
+ Check(Variant->hasFnAttribute(Attribute::AllocKind) &&
+ (Variant->getFnAttribute(Attribute::AllocKind).getAllocKind() &
+ AllocFnKind::Zeroed) != AllocFnKind::Unknown,
+ "'alloc-variant-zeroed' must name a function with "
+ "'allockind(\"zeroed\")'");
+
+ Check(FT == Variant->getFunctionType(),
+ "'alloc-variant-zeroed' must name a function with the same "
+ "signature");
+ }
+ }
+
if (Attrs.hasFnAttr(Attribute::VScaleRange)) {
unsigned VScaleMin = Attrs.getFnAttrs().getVScaleRangeMin();
if (VScaleMin == 0)