diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2022-12-08 10:53:17 -0500 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2022-12-14 13:12:35 -0500 |
commit | c16a58b36caebbc34dfa0f788a019d041e5484df (patch) | |
tree | f414679a49d47918a19469a1b1d23d5c95f24185 /llvm/lib/IR/Function.cpp | |
parent | 547e40a91b1e8e92add955a95a286999107c9196 (diff) | |
download | llvm-c16a58b36caebbc34dfa0f788a019d041e5484df.zip llvm-c16a58b36caebbc34dfa0f788a019d041e5484df.tar.gz llvm-c16a58b36caebbc34dfa0f788a019d041e5484df.tar.bz2 |
Attributes: Add function getter to parse integer string attributes
The most common case for string attributes parses them as integers. We
don't have a convenient way to do this, and as a result we have
inconsistent missing attribute and invalid attribute handling
scattered around. We also have inconsistent radix usage to
getAsInteger; some places use the default 0 and others use base 10.
Update a few of the uses, but there are quite a lot of these.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index f7a7751..10bbdcf 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -659,6 +659,19 @@ Attribute Function::getFnAttribute(StringRef Kind) const { return AttributeSets.getFnAttr(Kind); } +uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name, + uint64_t Default) const { + Attribute A = getFnAttribute(Name); + uint64_t Result = Default; + if (A.isStringAttribute()) { + StringRef Str = A.getValueAsString(); + if (Str.getAsInteger(0, Result)) + getContext().emitError("cannot parse integer attribute " + Name); + } + + return Result; +} + /// gets the specified attribute from the list of attributes. Attribute Function::getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const { |