[llvm] d664c4b - Attributes: add a new allocalign attribute
Augie Fackler via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 13:00:56 PST 2022
Author: Augie Fackler
Date: 2022-03-04T15:57:53-05:00
New Revision: d664c4b73c5dc994d4caa6c70bb5e59ada414b90
URL: https://github.com/llvm/llvm-project/commit/d664c4b73c5dc994d4caa6c70bb5e59ada414b90
DIFF: https://github.com/llvm/llvm-project/commit/d664c4b73c5dc994d4caa6c70bb5e59ada414b90.diff
LOG: Attributes: add a new allocalign attribute
This will let us start moving away from hard-coded attributes in
MemoryBuiltins.cpp and put the knowledge about various attribute
functions in the compilers that emit those calls where it probably
belongs.
Differential Revision: https://reviews.llvm.org/D117921
Added:
Modified:
llvm/docs/LangRef.rst
llvm/include/llvm/AsmParser/LLToken.h
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/test/Bitcode/compatibility.ll
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index be10ff12911a9..252cfc9285ec3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1379,6 +1379,14 @@ Currently, only the following parameter attributes are defined:
information that is not mapped to base types in the backend (for example,
over-alignment specification through language attributes).
+``allocalign``
+ The function parameter marked with this attribute is is the alignment in bytes of the
+ newly allocated block returned by this function. The returned value must either have
+ the specified alignment or be the null pointer. The return value MAY be more aligned
+ than the requested alignment, but not less aligned. Invalid (e.g. non-power-of-2)
+ alignments are permitted for the allocalign parameter, so long as the returned pointer
+ is null. This attribute may only be applied to integer parameters.
+
.. _gc:
Garbage Collector Strategy Names
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index 7b0cf69bce2d4..c4ccd358f938b 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -177,6 +177,7 @@ enum Kind {
// Attributes:
kw_attributes,
+ kw_allocalign,
kw_allocsize,
kw_alwaysinline,
kw_argmemonly,
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index a026b44bf32f2..1f6c13ef457b5 100644
--- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -678,6 +678,7 @@ enum AttributeKindCodes {
ATTR_KIND_ELEMENTTYPE = 77,
ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION = 78,
ATTR_KIND_NO_SANITIZE_BOUNDS = 79,
+ ATTR_KIND_ALLOC_ALIGN = 80,
};
enum ComdatSelectionKindCodes {
diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td
index 3065b75deb17c..66212a7da8b33 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -47,6 +47,10 @@ class StrBoolAttr<string S> : Attr<S, []>;
/// 0 means unaligned (
diff erent from align(1)).
def Alignment : IntAttr<"align", [ParamAttr, RetAttr]>;
+/// Parameter of a function that tells us the alignment of an allocation, as in
+/// aligned_alloc and aligned ::operator::new.
+def AllocAlign: EnumAttr<"allocalign", [ParamAttr]>;
+
/// The result of the function is guaranteed to point to a number of bytes that
/// we can determine if we know the value of the function's arguments.
def AllocSize : IntAttr<"allocsize", [FnAttr]>;
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 3f0c60fd571af..6048066a44fb7 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -634,6 +634,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(attributes);
KEYWORD(alwaysinline);
+ KEYWORD(allocalign);
KEYWORD(allocsize);
KEYWORD(argmemonly);
KEYWORD(builtin);
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index cba56802db63f..edeacf4955c3f 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1520,6 +1520,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::Dereferenceable;
case bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL:
return Attribute::DereferenceableOrNull;
+ case bitc::ATTR_KIND_ALLOC_ALIGN:
+ return Attribute::AllocAlign;
case bitc::ATTR_KIND_ALLOC_SIZE:
return Attribute::AllocSize;
case bitc::ATTR_KIND_NO_RED_ZONE:
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 6b5147ff7807d..c847118a352b1 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -610,6 +610,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
switch (Kind) {
case Attribute::Alignment:
return bitc::ATTR_KIND_ALIGNMENT;
+ case Attribute::AllocAlign:
+ return bitc::ATTR_KIND_ALLOC_ALIGN;
case Attribute::AllocSize:
return bitc::ATTR_KIND_ALLOC_SIZE;
case Attribute::AlwaysInline:
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index f88f75e23d9de..73c0f59ec1cc0 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1780,7 +1780,8 @@ AttributeMask AttributeFuncs::typeIncompatible(Type *Ty) {
if (!Ty->isIntegerTy())
// Attributes that only apply to integers.
Incompatible.addAttribute(Attribute::SExt)
- .addAttribute(Attribute::ZExt);
+ .addAttribute(Attribute::ZExt)
+ .addAttribute(Attribute::AllocAlign);
if (!Ty->isPointerTy())
// Attributes that only apply to pointers.
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 292234563e93c..9bb0596f2a2d5 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -962,6 +962,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
break;
// These attributes cannot be applied to functions.
case Attribute::Alignment:
+ case Attribute::AllocAlign:
case Attribute::ByVal:
case Attribute::Dereferenceable:
case Attribute::DereferenceableOrNull:
diff --git a/llvm/test/Bitcode/compatibility.ll b/llvm/test/Bitcode/compatibility.ll
index df8e0ac9ac3c7..5f973d69f8c33 100644
--- a/llvm/test/Bitcode/compatibility.ll
+++ b/llvm/test/Bitcode/compatibility.ll
@@ -560,6 +560,8 @@ declare void @f.param.swiftasync(i8* swiftasync)
; CHECK: declare void @f.param.swiftasync(i8* swiftasync)
declare void @f.param.swifterror(i8** swifterror)
; CHECK: declare void @f.param.swifterror(i8** swifterror)
+declare void @f.param.allocalign(i32 allocalign)
+; CHECK: declare void @f.param.allocalign(i32 allocalign)
; Functions -- unnamed_addr and local_unnamed_addr
declare void @f.unnamed_addr() unnamed_addr
More information about the llvm-commits
mailing list