@@ -436,6 +436,27 @@ class FailedToMaterialize : public ErrorInfo<FailedToMaterialize> {
436
436
std::shared_ptr<SymbolDependenceMap> Symbols;
437
437
};
438
438
439
+ // / Used to report failure due to unsatisfiable symbol dependencies.
440
+ class UnsatisfiedSymbolDependencies
441
+ : public ErrorInfo<UnsatisfiedSymbolDependencies> {
442
+ public:
443
+ static char ID;
444
+
445
+ UnsatisfiedSymbolDependencies (std::shared_ptr<SymbolStringPool> SSP,
446
+ JITDylibSP JD, SymbolNameSet FailedSymbols,
447
+ SymbolDependenceMap BadDeps,
448
+ std::string Explanation);
449
+ std::error_code convertToErrorCode () const override ;
450
+ void log (raw_ostream &OS) const override ;
451
+
452
+ private:
453
+ std::shared_ptr<SymbolStringPool> SSP;
454
+ JITDylibSP JD;
455
+ SymbolNameSet FailedSymbols;
456
+ SymbolDependenceMap BadDeps;
457
+ std::string Explanation;
458
+ };
459
+
439
460
// / Used to notify clients when symbols can not be found during a lookup.
440
461
class SymbolsNotFound : public ErrorInfo <SymbolsNotFound> {
441
462
public:
@@ -517,6 +538,13 @@ class UnexpectedSymbolDefinitions : public ErrorInfo<UnexpectedSymbolDefinitions
517
538
SymbolNameVector Symbols;
518
539
};
519
540
541
+ // / A set of symbols and the their dependencies. Used to describe dependencies
542
+ // / for the MaterializationResponsibility::notifyEmitted operation.
543
+ struct SymbolDependenceGroup {
544
+ SymbolNameSet Symbols;
545
+ SymbolDependenceMap Dependencies;
546
+ };
547
+
520
548
// / Tracks responsibility for materialization, and mediates interactions between
521
549
// / MaterializationUnits and JDs.
522
550
// /
@@ -587,13 +615,22 @@ class MaterializationResponsibility {
587
615
// / that all symbols covered by this MaterializationResponsibility instance
588
616
// / have been emitted.
589
617
// /
618
+ // / The DepGroups array describes the dependencies of symbols being emitted on
619
+ // / symbols that are outside this MaterializationResponsibility object. Each
620
+ // / group consists of a pair of a set of symbols and a SymbolDependenceMap
621
+ // / that describes the dependencies for the symbols in the first set. The
622
+ // / elements of DepGroups must be non-overlapping (no symbol should appear in
623
+ // / more than one of hte symbol sets), but do not have to be exhaustive. Any
624
+ // / symbol in this MaterializationResponsibility object that is not covered
625
+ // / by an entry will be treated as having no dependencies.
626
+ // /
590
627
// / This method will return an error if any symbols being resolved have been
591
628
// / moved to the error state due to the failure of a dependency. If this
592
629
// / method returns an error then clients should log it and call
593
630
// / failMaterialize. If no dependencies have been registered for the
594
631
// / symbols covered by this MaterializationResponsibility then this method
595
632
// / is guaranteed to return Error::success() and can be wrapped with cantFail.
596
- Error notifyEmitted ();
633
+ Error notifyEmitted (ArrayRef<SymbolDependenceGroup> DepGroups );
597
634
598
635
// / Attempt to claim responsibility for new definitions. This method can be
599
636
// / used to claim responsibility for symbols that are added to a
@@ -628,12 +665,6 @@ class MaterializationResponsibility {
628
665
Expected<std::unique_ptr<MaterializationResponsibility>>
629
666
delegate (const SymbolNameSet &Symbols);
630
667
631
- void addDependencies (const SymbolStringPtr &Name,
632
- const SymbolDependenceMap &Dependencies);
633
-
634
- // / Add dependencies that apply to all symbols covered by this instance.
635
- void addDependenciesForAll (const SymbolDependenceMap &Dependencies);
636
-
637
668
private:
638
669
// / Create a MaterializationResponsibility for the given JITDylib and
639
670
// / initial symbols.
@@ -1185,9 +1216,29 @@ class JITDylib : public ThreadSafeRefCountedBase<JITDylib>,
1185
1216
using UnmaterializedInfosList =
1186
1217
std::vector<std::shared_ptr<UnmaterializedInfo>>;
1187
1218
1219
+ struct EmissionDepUnit {
1220
+ EmissionDepUnit (JITDylib &JD) : JD(&JD) {}
1221
+
1222
+ JITDylib *JD = nullptr ;
1223
+ DenseMap<NonOwningSymbolStringPtr, JITSymbolFlags> Symbols;
1224
+ DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> Dependencies;
1225
+ };
1226
+
1227
+ struct EmissionDepUnitInfo {
1228
+ std::shared_ptr<EmissionDepUnit> EDU;
1229
+ DenseSet<EmissionDepUnit *> IntraEmitUsers;
1230
+ DenseMap<JITDylib *, DenseSet<NonOwningSymbolStringPtr>> NewDeps;
1231
+ };
1232
+
1233
+ // Information about not-yet-ready symbol.
1234
+ // * DefiningEDU will point to the EmissionDepUnit that defines the symbol.
1235
+ // * DependantEDUs will hold pointers to any EmissionDepUnits currently
1236
+ // waiting on this symbol.
1237
+ // * Pending queries holds any not-yet-completed queries that include this
1238
+ // symbol.
1188
1239
struct MaterializingInfo {
1189
- SymbolDependenceMap Dependants ;
1190
- SymbolDependenceMap UnemittedDependencies ;
1240
+ std::shared_ptr<EmissionDepUnit> DefiningEDU ;
1241
+ DenseSet<EmissionDepUnit *> DependantEDUs ;
1191
1242
1192
1243
void addQuery (std::shared_ptr<AsynchronousSymbolQuery> Q);
1193
1244
void removeQuery (const AsynchronousSymbolQuery &Q);
@@ -1278,17 +1329,8 @@ class JITDylib : public ThreadSafeRefCountedBase<JITDylib>,
1278
1329
1279
1330
Error resolve (MaterializationResponsibility &MR, const SymbolMap &Resolved);
1280
1331
1281
- Error emit (MaterializationResponsibility &MR, const SymbolFlagsMap &Emitted);
1282
-
1283
1332
void unlinkMaterializationResponsibility (MaterializationResponsibility &MR);
1284
1333
1285
- using FailedSymbolsWorklist =
1286
- std::vector<std::pair<JITDylib *, SymbolStringPtr>>;
1287
-
1288
- static std::pair<AsynchronousSymbolQuerySet,
1289
- std::shared_ptr<SymbolDependenceMap>>
1290
- failSymbols (FailedSymbolsWorklist);
1291
-
1292
1334
ExecutionSession &ES;
1293
1335
enum { Open, Closing, Closed } State = Open;
1294
1336
std::mutex GeneratorsMutex;
@@ -1767,19 +1809,45 @@ class ExecutionSession {
1767
1809
SymbolNameSet OL_getRequestedSymbols (const MaterializationResponsibility &MR);
1768
1810
Error OL_notifyResolved (MaterializationResponsibility &MR,
1769
1811
const SymbolMap &Symbols);
1770
- Error OL_notifyEmitted (MaterializationResponsibility &MR);
1812
+
1813
+ using EDUInfosMap =
1814
+ DenseMap<JITDylib::EmissionDepUnit *, JITDylib::EmissionDepUnitInfo>;
1815
+
1816
+ template <typename HandleNewDepFn>
1817
+ void propagateExtraEmitDeps (std::deque<JITDylib::EmissionDepUnit *> Worklist,
1818
+ EDUInfosMap &EDUInfos,
1819
+ HandleNewDepFn HandleNewDep);
1820
+ EDUInfosMap simplifyDepGroups (MaterializationResponsibility &MR,
1821
+ ArrayRef<SymbolDependenceGroup> EmittedDeps);
1822
+ void IL_makeEDUReady (std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1823
+ JITDylib::AsynchronousSymbolQuerySet &Queries);
1824
+ void IL_makeEDUEmitted (std::shared_ptr<JITDylib::EmissionDepUnit> EDU,
1825
+ JITDylib::AsynchronousSymbolQuerySet &Queries);
1826
+ bool IL_removeEDUDependence (JITDylib::EmissionDepUnit &EDU, JITDylib &DepJD,
1827
+ NonOwningSymbolStringPtr DepSym,
1828
+ EDUInfosMap &EDUInfos);
1829
+
1830
+ static Error makeJDClosedError (JITDylib::EmissionDepUnit &EDU,
1831
+ JITDylib &ClosedJD);
1832
+ static Error makeUnsatisfiedDepsError (JITDylib::EmissionDepUnit &EDU,
1833
+ JITDylib &BadJD, SymbolNameSet BadDeps);
1834
+
1835
+ Expected<JITDylib::AsynchronousSymbolQuerySet>
1836
+ IL_emit (MaterializationResponsibility &MR, EDUInfosMap EDUInfos);
1837
+ Error OL_notifyEmitted (MaterializationResponsibility &MR,
1838
+ ArrayRef<SymbolDependenceGroup> EmittedDeps);
1839
+
1771
1840
Error OL_defineMaterializing (MaterializationResponsibility &MR,
1772
1841
SymbolFlagsMap SymbolFlags);
1842
+
1843
+ std::pair<JITDylib::AsynchronousSymbolQuerySet,
1844
+ std::shared_ptr<SymbolDependenceMap>>
1845
+ IL_failSymbols (JITDylib &JD, const SymbolNameVector &SymbolsToFail);
1773
1846
void OL_notifyFailed (MaterializationResponsibility &MR);
1774
1847
Error OL_replace (MaterializationResponsibility &MR,
1775
1848
std::unique_ptr<MaterializationUnit> MU);
1776
1849
Expected<std::unique_ptr<MaterializationResponsibility>>
1777
1850
OL_delegate (MaterializationResponsibility &MR, const SymbolNameSet &Symbols);
1778
- void OL_addDependencies (MaterializationResponsibility &MR,
1779
- const SymbolStringPtr &Name,
1780
- const SymbolDependenceMap &Dependencies);
1781
- void OL_addDependenciesForAll (MaterializationResponsibility &MR,
1782
- const SymbolDependenceMap &Dependencies);
1783
1851
1784
1852
#ifndef NDEBUG
1785
1853
void dumpDispatchInfo (Task &T);
@@ -1965,8 +2033,9 @@ inline Error MaterializationResponsibility::notifyResolved(
1965
2033
return getExecutionSession ().OL_notifyResolved (*this , Symbols);
1966
2034
}
1967
2035
1968
- inline Error MaterializationResponsibility::notifyEmitted () {
1969
- return getExecutionSession ().OL_notifyEmitted (*this );
2036
+ inline Error MaterializationResponsibility::notifyEmitted (
2037
+ ArrayRef<SymbolDependenceGroup> EmittedDeps) {
2038
+ return getExecutionSession ().OL_notifyEmitted (*this , EmittedDeps);
1970
2039
}
1971
2040
1972
2041
inline Error MaterializationResponsibility::defineMaterializing (
@@ -1989,16 +2058,6 @@ MaterializationResponsibility::delegate(const SymbolNameSet &Symbols) {
1989
2058
return getExecutionSession ().OL_delegate (*this , Symbols);
1990
2059
}
1991
2060
1992
- inline void MaterializationResponsibility::addDependencies (
1993
- const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies) {
1994
- getExecutionSession ().OL_addDependencies (*this , Name, Dependencies);
1995
- }
1996
-
1997
- inline void MaterializationResponsibility::addDependenciesForAll (
1998
- const SymbolDependenceMap &Dependencies) {
1999
- getExecutionSession ().OL_addDependenciesForAll (*this , Dependencies);
2000
- }
2001
-
2002
2061
} // End namespace orc
2003
2062
} // End namespace llvm
2004
2063
0 commit comments