[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / tools / llvm-jitlink / llvm-jitlink.h
blob9389be4aa393cf5829afb04bac94a4d0768743fb
1 //===---- llvm-jitlink.h - Session and format-specific decls ----*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 //
9 // llvm-jitlink Session class and tool utilities.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
14 #define LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/ExecutionEngine/Orc/Core.h"
18 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
19 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
20 #include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
21 #include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/Regex.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/TargetParser/SubtargetFeature.h"
26 #include "llvm/TargetParser/Triple.h"
28 #include <vector>
30 namespace llvm {
32 struct Session {
34 orc::ExecutionSession ES;
35 orc::JITDylib *MainJD = nullptr;
36 orc::ObjectLinkingLayer ObjLayer;
37 orc::JITDylibSearchOrder JDSearchOrder;
38 SubtargetFeatures Features;
40 ~Session();
42 static Expected<std::unique_ptr<Session>> Create(Triple TT,
43 SubtargetFeatures Features);
44 void dumpSessionInfo(raw_ostream &OS);
45 void modifyPassConfig(const Triple &FTT,
46 jitlink::PassConfiguration &PassConfig);
48 using MemoryRegionInfo = RuntimeDyldChecker::MemoryRegionInfo;
50 struct FileInfo {
51 StringMap<MemoryRegionInfo> SectionInfos;
52 StringMap<MemoryRegionInfo> StubInfos;
53 StringMap<MemoryRegionInfo> GOTEntryInfos;
56 using DynLibJDMap = std::map<std::string, orc::JITDylib *>;
57 using SymbolInfoMap = StringMap<MemoryRegionInfo>;
58 using FileInfoMap = StringMap<FileInfo>;
60 Expected<orc::JITDylib *> getOrLoadDynamicLibrary(StringRef LibPath);
61 Error loadAndLinkDynamicLibrary(orc::JITDylib &JD, StringRef LibPath);
63 Expected<FileInfo &> findFileInfo(StringRef FileName);
64 Expected<MemoryRegionInfo &> findSectionInfo(StringRef FileName,
65 StringRef SectionName);
66 Expected<MemoryRegionInfo &> findStubInfo(StringRef FileName,
67 StringRef TargetName);
68 Expected<MemoryRegionInfo &> findGOTEntryInfo(StringRef FileName,
69 StringRef TargetName);
71 bool isSymbolRegistered(StringRef Name);
72 Expected<MemoryRegionInfo &> findSymbolInfo(StringRef SymbolName,
73 Twine ErrorMsgStem);
75 DynLibJDMap DynLibJDs;
77 SymbolInfoMap SymbolInfos;
78 FileInfoMap FileInfos;
80 StringSet<> HarnessFiles;
81 StringSet<> HarnessExternals;
82 StringSet<> HarnessDefinitions;
83 DenseMap<StringRef, StringRef> CanonicalWeakDefs;
85 std::optional<Regex> ShowGraphsRegex;
87 private:
88 Session(std::unique_ptr<orc::ExecutorProcessControl> EPC, Error &Err);
91 /// Record symbols, GOT entries, stubs, and sections for ELF file.
92 Error registerELFGraphInfo(Session &S, jitlink::LinkGraph &G);
94 /// Record symbols, GOT entries, stubs, and sections for MachO file.
95 Error registerMachOGraphInfo(Session &S, jitlink::LinkGraph &G);
97 /// Record symbols, GOT entries, stubs, and sections for COFF file.
98 Error registerCOFFGraphInfo(Session &S, jitlink::LinkGraph &G);
100 /// Adds a statistics gathering plugin if any stats options are used.
101 void enableStatistics(Session &S, bool UsingOrcRuntime);
103 } // end namespace llvm
105 #endif // LLVM_TOOLS_LLVM_JITLINK_LLVM_JITLINK_H