Skip to content

Commit 3bece3d

Browse files
authored
[Exegesis] Do not assume the size and layout of the assembled snippet (#79636)
Currently llvm-exegesis assumes that there will only be 3 symbols in the snippet object, in which the benchmarking function 'foo' is always the last symbol. These assumptions do not hold for object file formats of other targets we support downstream. I think it would be more ideal to generalize this part of the logics into a simple search on all symbols, as proposed by this patch.
1 parent 9816863 commit 3bece3d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,20 @@ Expected<ExecutableFunction> ExecutableFunction::create(
365365

366366
auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary());
367367
// Get the size of the function that we want to call into (with the name of
368-
// FunctionID). This should always be the third symbol returned by
369-
// calculateSymbolSizes.
370-
assert(SymbolSizes.size() == 3);
371-
assert(cantFail(std::get<0>(SymbolSizes[2]).getName()) == FunctionID);
372-
uintptr_t CodeSize = std::get<1>(SymbolSizes[2]);
368+
// FunctionID).
369+
auto SymbolIt = llvm::find_if(SymbolSizes, [&](const auto &Pair) {
370+
auto SymbolName = Pair.first.getName();
371+
if (SymbolName)
372+
return *SymbolName == FunctionID;
373+
// We should always succeed in finding the FunctionID, hence we suppress
374+
// the error here and assert later on the search result, rather than
375+
// propagating the Expected<> error back to the caller.
376+
llvm::consumeError(SymbolName.takeError());
377+
return false;
378+
});
379+
assert(SymbolIt != SymbolSizes.end() &&
380+
"Cannot find the symbol for FunctionID");
381+
uintptr_t CodeSize = SymbolIt->second;
373382

374383
auto EJITOrErr = orc::LLJITBuilder().create();
375384
if (!EJITOrErr)

0 commit comments

Comments
 (0)