[llvm] [llvm-ir2vec] Decoupling Vocab loading from initEmbedding (PR #190507)
S. VenkataKeerthy via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 5 09:15:12 PDT 2026
================
@@ -43,17 +43,21 @@ namespace llvm {
namespace ir2vec {
-Error IR2VecTool::initializeVocabulary(StringRef VocabPath) {
+Expected<std::shared_ptr<Vocabulary>> loadVocabulary(StringRef VocabPath) {
auto VocabOrErr = Vocabulary::fromFile(VocabPath);
if (!VocabOrErr)
return VocabOrErr.takeError();
- Vocab = std::make_unique<Vocabulary>(std::move(*VocabOrErr));
+ auto V = std::make_shared<Vocabulary>(std::move(*VocabOrErr));
- if (!Vocab->isValid())
+ if (!V->isValid())
return createStringError(errc::invalid_argument,
"Failed to initialize IR2Vec vocabulary");
- return Error::success();
+ return V;
+}
+
+void IR2VecTool::setVocabulary(std::shared_ptr<Vocabulary> V) {
+ Vocab = std::move(V);
----------------
svkeerthy wrote:
Assert `V` is not null and valid before.
```assert(V && V->isValid() && "Vocabulary must be non-null and valid");```
https://github.com/llvm/llvm-project/pull/190507
More information about the llvm-commits
mailing list