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

Skip to content

Commit 5877baf

Browse files
authored
[NFC][IR2Vec] Initialize Embedding vectors with zeros by default (#155690)
Initialize `Embedding` vectors with zeros by default when only size is provided.
1 parent 1a16bc1 commit 5877baf

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

llvm/include/llvm/Analysis/IR2Vec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct Embedding {
9292
Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
9393
Embedding(std::initializer_list<double> IL) : Data(IL) {}
9494

95-
explicit Embedding(size_t Size) : Data(Size) {}
95+
explicit Embedding(size_t Size) : Data(Size, 0.0) {}
9696
Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
9797

9898
size_t size() const { return Data.size(); }

llvm/lib/Analysis/IR2Vec.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void Embedding::print(raw_ostream &OS) const {
155155
Embedder::Embedder(const Function &F, const Vocabulary &Vocab)
156156
: F(F), Vocab(Vocab), Dimension(Vocab.getDimension()),
157157
OpcWeight(::OpcWeight), TypeWeight(::TypeWeight), ArgWeight(::ArgWeight),
158-
FuncVector(Embedding(Dimension, 0)) {}
158+
FuncVector(Embedding(Dimension)) {}
159159

160160
std::unique_ptr<Embedder> Embedder::create(IR2VecKind Mode, const Function &F,
161161
const Vocabulary &Vocab) {
@@ -472,7 +472,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
472472

473473
// Handle Opcodes
474474
std::vector<Embedding> NumericOpcodeEmbeddings(Vocabulary::MaxOpcodes,
475-
Embedding(Dim, 0));
475+
Embedding(Dim));
476476
NumericOpcodeEmbeddings.reserve(Vocabulary::MaxOpcodes);
477477
for (unsigned Opcode : seq(0u, Vocabulary::MaxOpcodes)) {
478478
StringRef VocabKey = Vocabulary::getVocabKeyForOpcode(Opcode + 1);
@@ -487,7 +487,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
487487

488488
// Handle Types - only canonical types are present in vocabulary
489489
std::vector<Embedding> NumericTypeEmbeddings(Vocabulary::MaxCanonicalTypeIDs,
490-
Embedding(Dim, 0));
490+
Embedding(Dim));
491491
NumericTypeEmbeddings.reserve(Vocabulary::MaxCanonicalTypeIDs);
492492
for (unsigned CTypeID : seq(0u, Vocabulary::MaxCanonicalTypeIDs)) {
493493
StringRef VocabKey = Vocabulary::getVocabKeyForCanonicalTypeID(
@@ -503,7 +503,7 @@ void IR2VecVocabAnalysis::generateNumMappedVocab() {
503503

504504
// Handle Arguments/Operands
505505
std::vector<Embedding> NumericArgEmbeddings(Vocabulary::MaxOperandKinds,
506-
Embedding(Dim, 0));
506+
Embedding(Dim));
507507
NumericArgEmbeddings.reserve(Vocabulary::MaxOperandKinds);
508508
for (unsigned OpKind : seq(0u, Vocabulary::MaxOperandKinds)) {
509509
Vocabulary::OperandKind Kind = static_cast<Vocabulary::OperandKind>(OpKind);

0 commit comments

Comments
 (0)