Add gfx950 mfma instructions to ROCDL dialect (#123361)
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / LookupAndRecordAddrs.cpp
blob78169a28ed63bd7d2e67efb6538ae8accefabaf4
1 //===------- LookupAndRecordAddrs.h - Symbol lookup support utility -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
11 #include <future>
13 namespace llvm {
14 namespace orc {
16 void lookupAndRecordAddrs(
17 unique_function<void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K,
18 const JITDylibSearchOrder &SearchOrder,
19 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
20 SymbolLookupFlags LookupFlags) {
22 SymbolLookupSet Symbols;
23 for (auto &KV : Pairs)
24 Symbols.add(KV.first, LookupFlags);
26 ES.lookup(
27 K, SearchOrder, std::move(Symbols), SymbolState::Ready,
28 [Pairs = std::move(Pairs),
29 OnRec = std::move(OnRecorded)](Expected<SymbolMap> Result) mutable {
30 if (!Result)
31 return OnRec(Result.takeError());
32 for (auto &KV : Pairs) {
33 auto I = Result->find(KV.first);
34 *KV.second =
35 I != Result->end() ? I->second.getAddress() : orc::ExecutorAddr();
37 OnRec(Error::success());
39 NoDependenciesToRegister);
42 Error lookupAndRecordAddrs(
43 ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder,
44 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
45 SymbolLookupFlags LookupFlags) {
47 std::promise<MSVCPError> ResultP;
48 auto ResultF = ResultP.get_future();
49 lookupAndRecordAddrs([&](Error Err) { ResultP.set_value(std::move(Err)); },
50 ES, K, SearchOrder, std::move(Pairs), LookupFlags);
51 return ResultF.get();
54 Error lookupAndRecordAddrs(
55 ExecutorProcessControl &EPC, tpctypes::DylibHandle H,
56 std::vector<std::pair<SymbolStringPtr, ExecutorAddr *>> Pairs,
57 SymbolLookupFlags LookupFlags) {
59 SymbolLookupSet Symbols;
60 for (auto &KV : Pairs)
61 Symbols.add(KV.first, LookupFlags);
63 DylibManager::LookupRequest LR(H, Symbols);
64 auto Result = EPC.getDylibMgr().lookupSymbols(LR);
65 if (!Result)
66 return Result.takeError();
68 if (Result->size() != 1)
69 return make_error<StringError>("Error in lookup result",
70 inconvertibleErrorCode());
71 if (Result->front().size() != Pairs.size())
72 return make_error<StringError>("Error in lookup result elements",
73 inconvertibleErrorCode());
75 for (unsigned I = 0; I != Pairs.size(); ++I)
76 *Pairs[I].second = Result->front()[I].getAddress();
78 return Error::success();
81 } // End namespace orc.
82 } // End namespace llvm.