Skip to content

[LLVM] Extend setModuleFlag interface. #86031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

DanielKristofKiss
Copy link
Member

@DanielKristofKiss DanielKristofKiss commented Mar 20, 2024

Add same interfaces variants to the Module::setModuleFlag as the Module::addModuleFlag has.

@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2024

@llvm/pr-subscribers-llvm-ir

Author: Daniel Kiss (DanielKristofKiss)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/86031.diff

3 Files Affected:

  • (modified) llvm/include/llvm/IR/Module.h (+2)
  • (modified) llvm/lib/IR/Module.cpp (+9)
  • (modified) llvm/unittests/IR/ModuleTest.cpp (+16)
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index bb2e667ef6f410..907aeaf7f67efa 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -542,6 +542,8 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   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 a8696ed9e3ce5d..25231f54313b33 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -397,6 +397,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 da684b85a4dfb5..c18301d5e6d758 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}
 

@DanielKristofKiss
Copy link
Member Author

CI failed with an unrelated timeout issue on Win machine.

@lattner lattner removed their request for review June 4, 2024 02:06
Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@DanielKristofKiss DanielKristofKiss merged commit 930dd3f into llvm:main Jun 20, 2024
3 of 4 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 20, 2024

LLVM Buildbot has detected a new failure on builder clang-cuda-l4 running on cuda-l4-0 while building llvm at step 3 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/101/builds/352

Here is the relevant piece of the build log for the reference:

Step 3 (annotate) failure: '/buildbot/cuda-build --jobs=' (failure)
...
  NV_LIBCUBLAS_PACKAGE_NAME=libcublas-12-2
  NV_LIBCUBLAS_VERSION=12.2.5.6-1
  NV_LIBCUSPARSE_VERSION=12.1.2.141-1
  NV_LIBNCCL_PACKAGE=libnccl2=2.18.5-1+cuda12.2
  NV_LIBNCCL_PACKAGE_NAME=libnccl2
  NV_LIBNCCL_PACKAGE_VERSION=2.18.5-1
  NV_LIBNPP_PACKAGE=libnpp-12-2=12.2.1.4-1
  NV_LIBNPP_VERSION=12.2.1.4-1
  NV_NVTX_VERSION=12.2.140-1
  PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/buildbot
  PWD=/buildbot/cuda-l4-0/work/cuda-l4-0/clang-cuda-l4/build
  SHLVL=1
  TERM=dumb
  WORK_DIR=/buildbot/cuda-l4-0/work
  _=/usr/local/bin/buildbot-worker
 using PTY: False
++ echo @@@HALT_ON_FAILURE@@@
++ readlink -f ..
+ buildbot_dir=/buildbot/cuda-l4-0/work/cuda-l4-0/clang-cuda-l4
+ revision=930dd3fd873c91556b878444d57b1d12651b266f
+ GPU_ARCH=sm_89
+ CUDA_TEST_JOBS=1
+ build_base=/buildbot/cuda-l4-0/work/clang-cuda-l4
+ mkdir -p /buildbot/cuda-l4-0/work/clang-cuda-l4
+ build_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/build
+ libc_build_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/build-libc
+ clang_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/clang
+ testsuite_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/llvm-test-suite
+ llvm_src_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/llvm
+ ext_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/external
+ inner_pid=253922
+ trap 'handle_termination $inner_pid' TERM
+ do_build_and_test
+ wait 253922
+ fetch_prebuilt_clang 930dd3fd873c91556b878444d57b1d12651b266f /buildbot/cuda-l4-0/work/clang-cuda-l4/clang
+ local revision=930dd3fd873c91556b878444d57b1d12651b266f
+ local destdir=/buildbot/cuda-l4-0/work/clang-cuda-l4/clang
+ local 'timeout=10 minutes'
++ date -ud '10 minutes' +%s
+ local endtime=1718866568
++ storage_location llvm-930dd3fd873c91556b878444d57b1d12651b266f
++ local file=llvm-930dd3fd873c91556b878444d57b1d12651b266f
++ local default_storage_prefix=gs://cudabot-gce-artifacts/
++ echo gs://cudabot-gce-artifacts/llvm-930dd3fd873c91556b878444d57b1d12651b266f
+ local snapshot=gs://cudabot-gce-artifacts/llvm-930dd3fd873c91556b878444d57b1d12651b266f
+ step 'Waiting for LLVM & Clang snapshot to be built. '
+ local 'name=Waiting for LLVM & Clang snapshot to be built. '
+ local summary=
+ echo '@@@BUILD_STEP Waiting for LLVM & Clang snapshot to be built. @@@'
+ step_summary_clear

AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
Add same interfaces variants to the `Module::setModuleFlag` as the
`Module::addModuleFlag` has.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants