diff options
author | Min-Yih Hsu <min.hsu@sifive.com> | 2024-01-26 15:47:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 15:47:26 -0800 |
commit | 3bece3d72d1323af6b2418b13281e66b583f25b3 (patch) | |
tree | 2cbc01f5ba45d9241fc7f73e4dfe96ff489b6fc7 /llvm/tools/llvm-exegesis/lib/Assembler.cpp | |
parent | 9816863dd439cd60c96d5764c4c21ca1a7f3d8da (diff) | |
download | llvm-3bece3d72d1323af6b2418b13281e66b583f25b3.zip llvm-3bece3d72d1323af6b2418b13281e66b583f25b3.tar.gz llvm-3bece3d72d1323af6b2418b13281e66b583f25b3.tar.bz2 |
[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.
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Assembler.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Assembler.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp index 9f03a4e..307b951 100644 --- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp +++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp @@ -365,11 +365,20 @@ Expected<ExecutableFunction> ExecutableFunction::create( auto SymbolSizes = object::computeSymbolSizes(*ObjectFileHolder.getBinary()); // Get the size of the function that we want to call into (with the name of - // FunctionID). This should always be the third symbol returned by - // calculateSymbolSizes. - assert(SymbolSizes.size() == 3); - assert(cantFail(std::get<0>(SymbolSizes[2]).getName()) == FunctionID); - uintptr_t CodeSize = std::get<1>(SymbolSizes[2]); + // FunctionID). + auto SymbolIt = llvm::find_if(SymbolSizes, [&](const auto &Pair) { + auto SymbolName = Pair.first.getName(); + if (SymbolName) + return *SymbolName == FunctionID; + // We should always succeed in finding the FunctionID, hence we suppress + // the error here and assert later on the search result, rather than + // propagating the Expected<> error back to the caller. + llvm::consumeError(SymbolName.takeError()); + return false; + }); + assert(SymbolIt != SymbolSizes.end() && + "Cannot find the symbol for FunctionID"); + uintptr_t CodeSize = SymbolIt->second; auto EJITOrErr = orc::LLJITBuilder().create(); if (!EJITOrErr) |