Skip to content

Commit 59b8fab

Browse files
committed
Changing Create factory method to return Expected<> instead of ErrorOr
1 parent d624c13 commit 59b8fab

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

llvm/docs/MLGO.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ embeddings can be computed and accessed via an ``ir2vec::Embedder`` instance.
225225

226226
// Assuming F is an llvm::Function&
227227
// For example, using IR2VecKind::Symbolic:
228-
ErrorOr<std::unique_ptr<ir2vec::Embedder>> EmbOrErr =
228+
Expected<std::unique_ptr<ir2vec::Embedder>> EmbOrErr =
229229
ir2vec::Embedder::create(IR2VecKind::Symbolic, F, Vocabulary, Dimension);
230230

231-
if (auto EC = EmbOrErr.getError()) {
231+
if (auto Err = EmbOrErr.takeError()) {
232232
// Handle error in embedder creation
233233
return;
234234
}

llvm/include/llvm/Analysis/IR2Vec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ class Embedder {
106106
virtual void computeEmbeddings() = 0;
107107

108108
/// Factory method to create an Embedder object.
109-
static ErrorOr<std::unique_ptr<Embedder>> create(IR2VecKind Mode,
110-
const Function &F,
111-
const Vocab &Vocabulary,
112-
unsigned Dimension);
109+
static Expected<std::unique_ptr<Embedder>> create(IR2VecKind Mode,
110+
const Function &F,
111+
const Vocab &Vocabulary,
112+
unsigned Dimension);
113113

114114
/// Returns a map containing instructions and the corresponding vector
115115
/// representations for a given module corresponding to the IR2Vec

llvm/lib/Analysis/IR2Vec.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ Embedder::Embedder(const Function &F, const Vocab &Vocabulary,
6666
OpcWeight(::OpcWeight), TypeWeight(::TypeWeight), ArgWeight(::ArgWeight) {
6767
}
6868

69-
ErrorOr<std::unique_ptr<Embedder>> Embedder::create(IR2VecKind Mode,
70-
const Function &F,
71-
const Vocab &Vocabulary,
72-
unsigned Dimension) {
69+
Expected<std::unique_ptr<Embedder>> Embedder::create(IR2VecKind Mode,
70+
const Function &F,
71+
const Vocab &Vocabulary,
72+
unsigned Dimension) {
7373
switch (Mode) {
7474
case IR2VecKind::Symbolic:
7575
return std::make_unique<SymbolicEmbedder>(F, Vocabulary, Dimension);
7676
default:
77-
return errorToErrorCode(
78-
make_error<StringError>("Unknown IR2VecKind", errc::invalid_argument));
77+
return make_error<StringError>("Unknown IR2VecKind",
78+
errc::invalid_argument);
7979
}
8080
}
8181

@@ -262,12 +262,13 @@ PreservedAnalyses IR2VecPrinterPass::run(Module &M,
262262

263263
auto Vocab = IR2VecVocabResult.getVocabulary();
264264
auto Dim = IR2VecVocabResult.getDimension();
265-
266265
for (Function &F : M) {
267-
ErrorOr<std::unique_ptr<Embedder>> EmbOrErr =
266+
Expected<std::unique_ptr<Embedder>> EmbOrErr =
268267
Embedder::create(IR2VecKind::Symbolic, F, Vocab, Dim);
269-
if (auto EC = EmbOrErr.getError()) {
270-
OS << "Error creating IR2Vec embeddings: " << EC.message() << "\n";
268+
if (auto Err = EmbOrErr.takeError()) {
269+
handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) {
270+
OS << "Error creating IR2Vec embeddings: " << EI.message() << "\n";
271+
});
271272
continue;
272273
}
273274

0 commit comments

Comments
 (0)