[PATCH] D92567: [CallBase] Add hasRetAttr version that takes StringRef.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 3 04:08:07 PST 2020
fhahn created this revision.
fhahn added reviewers: ahatanak, efriedma, jdoerfert.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: LLVM.
fhahn requested review of this revision.
This makes it slightly easier to deal with custom attributes and
CallBase already provides hasFnAttr versions that support both AttrKind
and StringRef arguments in a similar fashion.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92567
Files:
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/IR/Instructions.cpp
llvm/unittests/IR/InstructionsTest.cpp
Index: llvm/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -94,6 +94,11 @@
EXPECT_EQ(Call->getArgOperand(Idx)->getType(), Arg->getType());
Idx++;
}
+
+ Call->addAttribute(llvm::AttributeList::ReturnIndex,
+ Attribute::get(Call->getContext(), "test-str-attr"));
+ EXPECT_TRUE(Call->hasRetAttr("test-str-attr"));
+ EXPECT_FALSE(Call->hasRetAttr("not-on-call"));
}
TEST_F(ModuleWithFunctionTest, InvokeInst) {
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -322,16 +322,6 @@
return nullptr;
}
-bool CallBase::hasRetAttr(Attribute::AttrKind Kind) const {
- if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind))
- return true;
-
- // Look at the callee, if available.
- if (const Function *F = getCalledFunction())
- return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind);
- return false;
-}
-
/// Determine whether the argument or parameter has the given attribute.
bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
assert(ArgNo < getNumArgOperands() && "Param index out of bounds!");
Index: llvm/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/include/llvm/IR/InstrTypes.h
+++ llvm/include/llvm/IR/InstrTypes.h
@@ -1526,7 +1526,10 @@
}
/// Determine whether the return value has the given attribute.
- bool hasRetAttr(Attribute::AttrKind Kind) const;
+ bool hasRetAttr(Attribute::AttrKind Kind) const {
+ return hasRetAttrImpl(Kind);
+ }
+ bool hasRetAttr(StringRef Kind) const { return hasRetAttrImpl(Kind); }
/// Determine whether the argument or parameter has the given attribute.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const;
@@ -2205,6 +2208,16 @@
return hasFnAttrOnCalledFunction(Kind);
}
+
+ template <typename AttrKind> bool hasRetAttrImpl(AttrKind Kind) const {
+ if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind))
+ return true;
+
+ // Look at the callee, if available.
+ if (const Function *F = getCalledFunction())
+ return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind);
+ return false;
+ }
};
template <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92567.309220.patch
Type: text/x-patch
Size: 2463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201203/46902df8/attachment.bin>
More information about the llvm-commits
mailing list