Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / EPCDebugObjectRegistrar.cpp
blobb8969de5493686e459ef855dec523e699270253b
1 //===----- EPCDebugObjectRegistrar.cpp - EPC-based debug registration -----===//
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/EPCDebugObjectRegistrar.h"
11 #include "llvm/ExecutionEngine/Orc/Core.h"
12 #include "llvm/ExecutionEngine/Orc/Shared/SimplePackedSerialization.h"
13 #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
14 #include "llvm/Support/BinaryStreamWriter.h"
16 namespace llvm {
17 namespace orc {
19 Expected<std::unique_ptr<EPCDebugObjectRegistrar>> createJITLoaderGDBRegistrar(
20 ExecutionSession &ES,
21 std::optional<ExecutorAddr> RegistrationFunctionDylib) {
22 auto &EPC = ES.getExecutorProcessControl();
24 if (!RegistrationFunctionDylib) {
25 if (auto D = EPC.loadDylib(nullptr))
26 RegistrationFunctionDylib = *D;
27 else
28 return D.takeError();
31 SymbolStringPtr RegisterFn =
32 EPC.getTargetTriple().isOSBinFormatMachO()
33 ? EPC.intern("_llvm_orc_registerJITLoaderGDBWrapper")
34 : EPC.intern("llvm_orc_registerJITLoaderGDBWrapper");
36 SymbolLookupSet RegistrationSymbols;
37 RegistrationSymbols.add(RegisterFn);
39 auto Result =
40 EPC.lookupSymbols({{*RegistrationFunctionDylib, RegistrationSymbols}});
41 if (!Result)
42 return Result.takeError();
44 assert(Result->size() == 1 && "Unexpected number of dylibs in result");
45 assert((*Result)[0].size() == 1 &&
46 "Unexpected number of addresses in result");
48 return std::make_unique<EPCDebugObjectRegistrar>(ES, (*Result)[0][0]);
51 Error EPCDebugObjectRegistrar::registerDebugObject(ExecutorAddrRange TargetMem,
52 bool AutoRegisterCode) {
53 return ES.callSPSWrapper<void(shared::SPSExecutorAddrRange, bool)>(
54 RegisterFn, TargetMem, AutoRegisterCode);
57 } // namespace orc
58 } // namespace llvm