diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-07-11 16:54:03 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-07-12 22:13:38 +0200 |
commit | 7ed3e87825b48747bc5e4fb6daa1f08b543c4ec9 (patch) | |
tree | 2508dc24690e3dd176cfb44f9140174a588d0d17 /llvm/lib/IR/Attributes.cpp | |
parent | e5e291e13502cdce6eafcb971c8e8beb2754f244 (diff) | |
download | llvm-7ed3e87825b48747bc5e4fb6daa1f08b543c4ec9.zip llvm-7ed3e87825b48747bc5e4fb6daa1f08b543c4ec9.tar.gz llvm-7ed3e87825b48747bc5e4fb6daa1f08b543c4ec9.tar.bz2 |
[Attributes] Determine attribute properties from TableGen data
Continuing from D105763, this allows placing certain properties
about attributes in the TableGen definition. In particular, we
store whether an attribute applies to fn/param/ret (or a combination
thereof). This information is used by the Verifier, as well as the
ForceFunctionAttrs pass. I also plan to use this in LLParser,
which also duplicates info on which attributes are valid where.
This keeps metadata about attributes in one place, and makes it
more likely that it stays in sync, rather than in various
functions spread across the codebase.
Differential Revision: https://reviews.llvm.org/D105780
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 3a4d82b..beb8a24 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -485,6 +485,35 @@ void Attribute::Profile(FoldingSetNodeID &ID) const { ID.AddPointer(pImpl); } +enum AttributeProperty { + FnAttr = (1 << 0), + ParamAttr = (1 << 1), + RetAttr = (1 << 2), +}; + +#define GET_ATTR_PROP_TABLE +#include "llvm/IR/Attributes.inc" + +static bool hasAttributeProperty(Attribute::AttrKind Kind, + AttributeProperty Prop) { + unsigned Index = Kind - 1; + assert(Index < sizeof(AttrPropTable) / sizeof(AttrPropTable[0]) && + "Invalid attribute kind"); + return AttrPropTable[Index] & Prop; +} + +bool Attribute::canUseAsFnAttr(AttrKind Kind) { + return hasAttributeProperty(Kind, AttributeProperty::FnAttr); +} + +bool Attribute::canUseAsParamAttr(AttrKind Kind) { + return hasAttributeProperty(Kind, AttributeProperty::ParamAttr); +} + +bool Attribute::canUseAsRetAttr(AttrKind Kind) { + return hasAttributeProperty(Kind, AttributeProperty::RetAttr); +} + //===----------------------------------------------------------------------===// // AttributeImpl Definition //===----------------------------------------------------------------------===// |