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

Skip to content

Conversation

svkeerthy
Copy link
Contributor

@svkeerthy svkeerthy commented Aug 27, 2025

Initialize Embedding vectors with zeros by default when only size is provided.

@svkeerthy svkeerthy changed the title Default constructor [NFC][IR2Vec] Initialize Embedding vectors with zeros by default Aug 27, 2025
@svkeerthy svkeerthy marked this pull request as ready for review August 27, 2025 20:27
@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Aug 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-llvm-analysis

Author: S. VenkataKeerthy (svkeerthy)

Changes

Initialize Embedding vectors with zeros by default when only size is provided.


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

2 Files Affected:

  • (modified) llvm/include/llvm/Analysis/IR2Vec.h (+1-1)
  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+4-4)
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h
index 44932a3385e16..6fb8f736da092 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -92,7 +92,7 @@ struct Embedding {
   Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
   Embedding(std::initializer_list<double> IL) : Data(IL) {}
 
-  explicit Embedding(size_t Size) : Data(Size) {}
+  explicit Embedding(size_t Size) : Data(Size, 0.0) {}
   Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
 
   size_t size() const { return Data.size(); }
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 565ec2a6287b7..6b90f1aabacfa 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -155,7 +155,7 @@ void Embedding::print(raw_ostream &OS) const {
 Embedder::Embedder(const Function &F, const Vocabulary &Vocab)
     : F(F), Vocab(Vocab), Dimension(Vocab.getDimension()),
       OpcWeight(::OpcWeight), TypeWeight(::TypeWeight), ArgWeight(::ArgWeight),
-      FuncVector(Embedding(Dimension, 0)) {}
+      FuncVector(Embedding(Dimension)) {}
 
 std::unique_ptr<Embedder> Embedder::create(IR2VecKind Mode, const Function &F,
                                            const Vocabulary &Vocab) {
@@ -472,7 +472,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Opcodes
   std::vector<Embedding> NumericOpcodeEmbeddings(Vocabulary::MaxOpcodes,
-                                                 Embedding(Dim, 0));
+                                                 Embedding(Dim));
   NumericOpcodeEmbeddings.reserve(Vocabulary::MaxOpcodes);
   for (unsigned Opcode : seq(0u, Vocabulary::MaxOpcodes)) {
     StringRef VocabKey = Vocabulary::getVocabKeyForOpcode(Opcode + 1);
@@ -487,7 +487,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Types - only canonical types are present in vocabulary
   std::vector<Embedding> NumericTypeEmbeddings(Vocabulary::MaxCanonicalTypeIDs,
-                                               Embedding(Dim, 0));
+                                               Embedding(Dim));
   NumericTypeEmbeddings.reserve(Vocabulary::MaxCanonicalTypeIDs);
   for (unsigned CTypeID : seq(0u, Vocabulary::MaxCanonicalTypeIDs)) {
     StringRef VocabKey = Vocabulary::getVocabKeyForCanonicalTypeID(
@@ -503,7 +503,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Arguments/Operands
   std::vector<Embedding> NumericArgEmbeddings(Vocabulary::MaxOperandKinds,
-                                              Embedding(Dim, 0));
+                                              Embedding(Dim));
   NumericArgEmbeddings.reserve(Vocabulary::MaxOperandKinds);
   for (unsigned OpKind : seq(0u, Vocabulary::MaxOperandKinds)) {
     Vocabulary::OperandKind Kind = static_cast<Vocabulary::OperandKind>(OpKind);

@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-mlgo

Author: S. VenkataKeerthy (svkeerthy)

Changes

Initialize Embedding vectors with zeros by default when only size is provided.


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

2 Files Affected:

  • (modified) llvm/include/llvm/Analysis/IR2Vec.h (+1-1)
  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+4-4)
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h
index 44932a3385e16..6fb8f736da092 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -92,7 +92,7 @@ struct Embedding {
   Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
   Embedding(std::initializer_list<double> IL) : Data(IL) {}
 
-  explicit Embedding(size_t Size) : Data(Size) {}
+  explicit Embedding(size_t Size) : Data(Size, 0.0) {}
   Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
 
   size_t size() const { return Data.size(); }
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 565ec2a6287b7..6b90f1aabacfa 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -155,7 +155,7 @@ void Embedding::print(raw_ostream &OS) const {
 Embedder::Embedder(const Function &F, const Vocabulary &Vocab)
     : F(F), Vocab(Vocab), Dimension(Vocab.getDimension()),
       OpcWeight(::OpcWeight), TypeWeight(::TypeWeight), ArgWeight(::ArgWeight),
-      FuncVector(Embedding(Dimension, 0)) {}
+      FuncVector(Embedding(Dimension)) {}
 
 std::unique_ptr<Embedder> Embedder::create(IR2VecKind Mode, const Function &F,
                                            const Vocabulary &Vocab) {
@@ -472,7 +472,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Opcodes
   std::vector<Embedding> NumericOpcodeEmbeddings(Vocabulary::MaxOpcodes,
-                                                 Embedding(Dim, 0));
+                                                 Embedding(Dim));
   NumericOpcodeEmbeddings.reserve(Vocabulary::MaxOpcodes);
   for (unsigned Opcode : seq(0u, Vocabulary::MaxOpcodes)) {
     StringRef VocabKey = Vocabulary::getVocabKeyForOpcode(Opcode + 1);
@@ -487,7 +487,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Types - only canonical types are present in vocabulary
   std::vector<Embedding> NumericTypeEmbeddings(Vocabulary::MaxCanonicalTypeIDs,
-                                               Embedding(Dim, 0));
+                                               Embedding(Dim));
   NumericTypeEmbeddings.reserve(Vocabulary::MaxCanonicalTypeIDs);
   for (unsigned CTypeID : seq(0u, Vocabulary::MaxCanonicalTypeIDs)) {
     StringRef VocabKey = Vocabulary::getVocabKeyForCanonicalTypeID(
@@ -503,7 +503,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
 
   // Handle Arguments/Operands
   std::vector<Embedding> NumericArgEmbeddings(Vocabulary::MaxOperandKinds,
-                                              Embedding(Dim, 0));
+                                              Embedding(Dim));
   NumericArgEmbeddings.reserve(Vocabulary::MaxOperandKinds);
   for (unsigned OpKind : seq(0u, Vocabulary::MaxOperandKinds)) {
     Vocabulary::OperandKind Kind = static_cast<Vocabulary::OperandKind>(OpKind);

@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from 9a18f1c to 7ddfeaa Compare August 27, 2025 21:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch from 51b1cd4 to 7ec3927 Compare August 27, 2025 21:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from 7ddfeaa to c809d9d Compare August 28, 2025 20:00
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch 2 times, most recently from f01119a to f82d77f Compare August 28, 2025 23:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from c809d9d to 18675c6 Compare August 28, 2025 23:04
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from 18675c6 to 374bfa9 Compare August 28, 2025 23:53
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch 2 times, most recently from f0b3c0c to a9edd27 Compare August 29, 2025 00:37
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch 2 times, most recently from 97560b9 to a20fb0e Compare August 29, 2025 18:52
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch from a9edd27 to 493f471 Compare August 29, 2025 18:53
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from a20fb0e to b21b641 Compare August 29, 2025 20:08
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch 2 times, most recently from ec2e1e1 to da83ad8 Compare September 3, 2025 22:30
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from b21b641 to 5c658e1 Compare September 3, 2025 22:30
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-26-added_doc branch from 5c658e1 to 0d74ab7 Compare September 4, 2025 19:07
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch from da83ad8 to 8c8500c Compare September 4, 2025 19:07
Base automatically changed from users/svkeerthy/08-26-added_doc to main September 4, 2025 19:42
@svkeerthy svkeerthy force-pushed the users/svkeerthy/08-27-default_constructor branch from 8c8500c to fd4e1df Compare September 4, 2025 19:43
Copy link
Contributor Author

svkeerthy commented Sep 4, 2025

Merge activity

  • Sep 4, 8:29 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Sep 4, 8:31 PM UTC: @svkeerthy merged this pull request with Graphite.

@svkeerthy svkeerthy merged commit 5877baf into main Sep 4, 2025
9 checks passed
@svkeerthy svkeerthy deleted the users/svkeerthy/08-27-default_constructor branch September 4, 2025 20:31
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.

3 participants