Skip to content

Commit 6bb850a

Browse files
committed
Minor changes to address comments
1 parent 6a8b450 commit 6bb850a

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

llvm/include/llvm/Analysis/IR2Vec.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,7 @@ class SymbolicEmbedder : public Embedder {
155155

156156
} // namespace ir2vec
157157

158-
class IR2VecVocabResult;
159-
160-
/// This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
161-
/// mapping between an entity of the IR (like opcode, type, argument, etc.) and
162-
/// its corresponding embedding.
163-
class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
164-
ir2vec::Vocab Vocabulary;
165-
Error readVocabulary();
166-
167-
public:
168-
static AnalysisKey Key;
169-
IR2VecVocabAnalysis() = default;
170-
using Result = IR2VecVocabResult;
171-
Result run(Module &M, ModuleAnalysisManager &MAM);
172-
};
173-
158+
/// Class for storing the result of the IR2VecVocabAnalysis.
174159
class IR2VecVocabResult {
175160
ir2vec::Vocab Vocabulary;
176161
bool Valid = false;
@@ -186,6 +171,20 @@ class IR2VecVocabResult {
186171
ModuleAnalysisManager::Invalidator &Inv);
187172
};
188173

174+
/// This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
175+
/// mapping between an entity of the IR (like opcode, type, argument, etc.) and
176+
/// its corresponding embedding.
177+
class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
178+
ir2vec::Vocab Vocabulary;
179+
Error readVocabulary();
180+
181+
public:
182+
static AnalysisKey Key;
183+
IR2VecVocabAnalysis() = default;
184+
using Result = IR2VecVocabResult;
185+
Result run(Module &M, ModuleAnalysisManager &MAM);
186+
};
187+
189188
/// This pass prints the IR2Vec embeddings for instructions, basic blocks, and
190189
/// functions.
191190
class IR2VecPrinterPass : public PassInfoMixin<IR2VecPrinterPass> {

llvm/lib/Analysis/IR2Vec.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Embedding SymbolicEmbedder::getOperandEmbedding(const Value *Op) {
134134
void SymbolicEmbedder::computeEmbeddings() {
135135
if (F.isDeclaration())
136136
return;
137-
for (auto &BB : F) {
137+
for (const auto &BB : F) {
138138
auto [It, WasInserted] = BBVecMap.try_emplace(&BB, computeBB2Vec(BB));
139139
assert(WasInserted && "Basic block already exists in the map");
140140
addVectors(FuncVector, It->second);
@@ -144,7 +144,7 @@ void SymbolicEmbedder::computeEmbeddings() {
144144
Embedding SymbolicEmbedder::computeBB2Vec(const BasicBlock &BB) {
145145
Embedding BBVector(Dimension, 0);
146146

147-
for (auto &I : BB) {
147+
for (const auto &I : BB) {
148148
Embedding InstVector(Dimension, 0);
149149

150150
auto OpcVec = lookupVocab(I.getOpcodeName());
@@ -245,7 +245,7 @@ IR2VecVocabAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
245245

246246
void IR2VecPrinterPass::printVector(const Embedding &Vec) const {
247247
OS << " [";
248-
for (auto &Elem : Vec)
248+
for (const auto &Elem : Vec)
249249
OS << " " << format("%.2f", Elem) << " ";
250250
OS << "]\n";
251251
}

0 commit comments

Comments
 (0)