aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kiss <daniel.kiss@arm.com>2024-06-20 08:45:35 +0200
committerGitHub <noreply@github.com>2024-06-20 08:45:35 +0200
commit930dd3fd873c91556b878444d57b1d12651b266f (patch)
treecf40517a7a3de18a939bfa6a84cfa44c0f34ed83
parent799e3c9e1713c3a52e45f071786a9748c4308c01 (diff)
downloadllvm-930dd3fd873c91556b878444d57b1d12651b266f.zip
llvm-930dd3fd873c91556b878444d57b1d12651b266f.tar.gz
llvm-930dd3fd873c91556b878444d57b1d12651b266f.tar.bz2
[LLVM] Extend setModuleFlag interface. (#86031)
Add same interfaces variants to the `Module::setModuleFlag` as the `Module::addModuleFlag` has.
-rw-r--r--llvm/include/llvm/IR/Module.h2
-rw-r--r--llvm/lib/IR/Module.cpp9
-rw-r--r--llvm/unittests/IR/ModuleTest.cpp16
3 files changed, 27 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 6135e15..d2b2fe4 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -548,6 +548,8 @@ public:
void addModuleFlag(MDNode *Node);
/// Like addModuleFlag but replaces the old module flag if it already exists.
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
+ void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
+ void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
/// @}
/// @name Materialization
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 55c282c..16c7944 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -399,6 +399,15 @@ void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
}
addModuleFlag(Behavior, Key, Val);
}
+void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
+ Constant *Val) {
+ setModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
+}
+void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
+ uint32_t Val) {
+ Type *Int32Ty = Type::getInt32Ty(Context);
+ setModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
+}
void Module::setDataLayout(StringRef Desc) {
DL.reset(Desc);
diff --git a/llvm/unittests/IR/ModuleTest.cpp b/llvm/unittests/IR/ModuleTest.cpp
index da684b8..c18301d 100644
--- a/llvm/unittests/IR/ModuleTest.cpp
+++ b/llvm/unittests/IR/ModuleTest.cpp
@@ -8,6 +8,7 @@
#include "llvm/IR/Module.h"
#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/Pass.h"
@@ -86,6 +87,21 @@ TEST(ModuleTest, setModuleFlag) {
EXPECT_EQ(Val2, M.getModuleFlag(Key));
}
+TEST(ModuleTest, setModuleFlagInt) {
+ LLVMContext Context;
+ Module M("M", Context);
+ StringRef Key = "Key";
+ uint32_t Val1 = 1;
+ uint32_t Val2 = 2;
+ EXPECT_EQ(nullptr, M.getModuleFlag(Key));
+ M.setModuleFlag(Module::ModFlagBehavior::Error, Key, Val1);
+ auto A1 = mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(Key));
+ EXPECT_EQ(Val1, A1->getZExtValue());
+ M.setModuleFlag(Module::ModFlagBehavior::Error, Key, Val2);
+ auto A2 = mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(Key));
+ EXPECT_EQ(Val2, A2->getZExtValue());
+}
+
const char *IRString = R"IR(
!llvm.module.flags = !{!0}