Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

svkeerthy
Copy link
Contributor

@svkeerthy svkeerthy commented Aug 11, 2025

Consolidate IR2Vec option categories to use a single shared category across the library and tool.

With this change the cl options defined in IR2Vec.cpp are visible in llvm-ir2vec tool. This is necessary as we use the same options in the tool.

@svkeerthy svkeerthy changed the title Merging IR2Vec Categories [IR2Vec] Make IR2VecCategory externally visible and reuse in llvm-ir2vec cl options Aug 11, 2025
@svkeerthy svkeerthy marked this pull request as ready for review August 11, 2025 21:38
@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Aug 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2025

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: S. VenkataKeerthy (svkeerthy)

Changes

Consolidate IR2Vec option categories to use a single shared category across the library and tool.

With this change the cl options defined in IR2Vec.cpp are visible in llvm-ir2vec tool. This is necessary as we use the same options in the tool.


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

3 Files Affected:

  • (modified) llvm/include/llvm/Analysis/IR2Vec.h (+1)
  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+1-1)
  • (modified) llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp (+5-7)
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h
index 3cfc206c94788..7ace83ba1d053 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -63,6 +63,7 @@ enum class IR2VecKind { Symbolic, FlowAware };
 
 namespace ir2vec {
 
+LLVM_EXTERNAL_VISIBILITY extern llvm::cl::OptionCategory IR2VecCategory;
 LLVM_ABI extern cl::opt<float> OpcWeight;
 LLVM_ABI extern cl::opt<float> TypeWeight;
 LLVM_ABI extern cl::opt<float> ArgWeight;
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 081a4d073b65f..e28938b64bfdb 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -36,7 +36,7 @@ STATISTIC(VocabMissCounter,
 
 namespace llvm {
 namespace ir2vec {
-static cl::OptionCategory IR2VecCategory("IR2Vec Options");
+LLVM_EXTERNAL_VISIBILITY cl::OptionCategory IR2VecCategory("IR2Vec Options");
 
 // FIXME: Use a default vocab when not specified
 static cl::opt<std::string>
diff --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index 8f8b4e2f2bda8..c065aaeedd395 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -55,8 +55,6 @@
 namespace llvm {
 namespace ir2vec {
 
-static cl::OptionCategory IR2VecToolCategory("IR2Vec Tool Options");
-
 // Subcommands
 static cl::SubCommand
     TripletsSubCmd("triplets", "Generate triplets for vocabulary training");
@@ -72,18 +70,18 @@ static cl::opt<std::string>
     InputFilename(cl::Positional,
                   cl::desc("<input bitcode file or '-' for stdin>"),
                   cl::init("-"), cl::sub(TripletsSubCmd),
-                  cl::sub(EmbeddingsSubCmd), cl::cat(IR2VecToolCategory));
+                  cl::sub(EmbeddingsSubCmd), cl::cat(ir2vec::IR2VecCategory));
 
 static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
                                            cl::value_desc("filename"),
                                            cl::init("-"),
-                                           cl::cat(IR2VecToolCategory));
+                                           cl::cat(ir2vec::IR2VecCategory));
 
 // Embedding-specific options
 static cl::opt<std::string>
     FunctionName("function", cl::desc("Process specific function only"),
                  cl::value_desc("name"), cl::Optional, cl::init(""),
-                 cl::sub(EmbeddingsSubCmd), cl::cat(IR2VecToolCategory));
+                 cl::sub(EmbeddingsSubCmd), cl::cat(ir2vec::IR2VecCategory));
 
 enum EmbeddingLevel {
   InstructionLevel, // Generate instruction-level embeddings
@@ -100,7 +98,7 @@ static cl::opt<EmbeddingLevel>
                      clEnumValN(FunctionLevel, "func",
                                 "Generate function-level embeddings")),
           cl::init(FunctionLevel), cl::sub(EmbeddingsSubCmd),
-          cl::cat(IR2VecToolCategory));
+          cl::cat(ir2vec::IR2VecCategory));
 
 namespace {
 
@@ -325,7 +323,7 @@ int main(int argc, char **argv) {
   using namespace llvm::ir2vec;
 
   InitLLVM X(argc, argv);
-  cl::HideUnrelatedOptions(IR2VecToolCategory);
+  cl::HideUnrelatedOptions(ir2vec::IR2VecCategory);
   cl::ParseCommandLineOptions(
       argc, argv,
       "IR2Vec - Embedding Generation Tool\n"

@@ -36,7 +36,7 @@ STATISTIC(VocabMissCounter,

namespace llvm {
namespace ir2vec {
static cl::OptionCategory IR2VecCategory("IR2Vec Options");
LLVM_EXTERNAL_VISIBILITY cl::OptionCategory IR2VecCategory("IR2Vec Options");
Copy link
Contributor

Choose a reason for hiding this comment

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

You need LLVM_EXTERNAL_VISIBILITY on the declaration and the definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems LLVM_EXTERNAL_VISIBILITY is not necessary. Removed it in both the places.

@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings branch from be6f9a6 to 0310cb4 Compare August 25, 2025 22:59
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from 44c5895 to de8480b Compare August 25, 2025 22:59
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch 2 times, most recently from 11de2dc to cbc8c9e Compare August 27, 2025 20:06
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings branch from 0310cb4 to 630f4af Compare August 27, 2025 20:06
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings branch from 630f4af to 87eed21 Compare August 27, 2025 21:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from cbc8c9e to 4da0ac5 Compare August 27, 2025 21:04
Copy link
Contributor Author

svkeerthy commented Aug 28, 2025

Merge activity

  • Aug 28, 6:26 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 28, 7:12 PM UTC: The Graphite merge of this pull request was cancelled.
  • Aug 29, 6:47 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 29, 6:49 PM UTC: @svkeerthy merged this pull request with Graphite.

@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings branch from 87eed21 to 1fdd3b3 Compare August 28, 2025 19:57
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from 4da0ac5 to b71c5ee Compare August 28, 2025 19:58
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from b71c5ee to b131bef Compare August 28, 2025 23:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings branch from 1fdd3b3 to 66d8de1 Compare August 28, 2025 23:04
Base automatically changed from users/svkeerthy/08-11-_ir2vec_llvm-ir2vec_supporting_flow-aware_embeddings to main August 28, 2025 23:48
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from b131bef to 7495b65 Compare August 28, 2025 23:52
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-11-merging_ir2vec_categories branch from 7495b65 to 829eb24 Compare August 29, 2025 00:37
@svkeerthy svkeerthy merged commit 3f8081d into main Aug 29, 2025
9 checks passed
@svkeerthy svkeerthy deleted the users/svkeerthy/08-11-merging_ir2vec_categories branch August 29, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding mlgo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants