[llvm] 85a13c7 - [IR] Add interface to remove a CallBase string function attribute
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 08:47:28 PDT 2023
Author: Teresa Johnson
Date: 2023-04-26T08:47:15-07:00
New Revision: 85a13c716fdcb1cc59eda1ce6d8e52397edc07fd
URL: https://github.com/llvm/llvm-project/commit/85a13c716fdcb1cc59eda1ce6d8e52397edc07fd
DIFF: https://github.com/llvm/llvm-project/commit/85a13c716fdcb1cc59eda1ce6d8e52397edc07fd.diff
LOG: [IR] Add interface to remove a CallBase string function attribute
Adds an interface to remove a string function attribute attached to a
CallBase, and a corresponding unittest.
This was extracted from D141077, and will be used by a follow on patch
that removes memprof attributes when needed.
Reviewed By: snehasish
Differential Revision: https://reviews.llvm.org/D149192
Added:
Modified:
llvm/include/llvm/IR/InstrTypes.h
llvm/unittests/IR/InstructionsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 980a46073d493..53aff55cc2c4f 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1559,6 +1559,11 @@ class CallBase : public Instruction {
Attrs = Attrs.removeFnAttribute(getContext(), Kind);
}
+ /// Removes the attribute from the function
+ void removeFnAttr(StringRef Kind) {
+ Attrs = Attrs.removeFnAttribute(getContext(), Kind);
+ }
+
/// Removes the attribute from the return value
void removeRetAttr(Attribute::AttrKind Kind) {
Attrs = Attrs.removeRetAttribute(getContext(), Kind);
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp
index eb506f6c9e4f3..b43a8c0bc5e60 100644
--- a/llvm/unittests/IR/InstructionsTest.cpp
+++ b/llvm/unittests/IR/InstructionsTest.cpp
@@ -102,6 +102,11 @@ TEST_F(ModuleWithFunctionTest, CallInst) {
Call->addRetAttr(Attribute::get(Call->getContext(), "test-str-attr"));
EXPECT_TRUE(Call->hasRetAttr("test-str-attr"));
EXPECT_FALSE(Call->hasRetAttr("not-on-call"));
+
+ Call->addFnAttr(Attribute::get(Call->getContext(), "test-str-fn-attr"));
+ ASSERT_TRUE(Call->hasFnAttr("test-str-fn-attr"));
+ Call->removeFnAttr("test-str-fn-attr");
+ EXPECT_FALSE(Call->hasFnAttr("test-str-fn-attr"));
}
TEST_F(ModuleWithFunctionTest, InvokeInst) {
More information about the llvm-commits
mailing list