[llvm] (WIP)(RFC)[MachineScheduler] A new approach to computing memory dependencies (PR #205689)
Valeriy Savchenko via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 02:43:40 PDT 2026
================
@@ -945,60 +881,116 @@ void ScheduleDAGInstrs::buildSchedGraph(AAResults *AA,
if (MI.mayStore()) {
if (!ObjsFound) {
- // An unknown store depends on all stores and loads.
- addChainDependencies(SU, Stores);
- addChainDependencies(SU, NonAliasStores);
- addChainDependencies(SU, Loads);
- addChainDependencies(SU, NonAliasLoads);
+ UnknownValueFrontier &Frontier =
+ Frontiers[0 /* TODO get address spaces for SU */];
+
+ bool IsSequencing = false;
+ for (const ValueType V : Objs) {
+ if (llvm::all_of(Frontier.BaseObjects,
+ [=](ValueType Base) { return Base != V; })) {
+ IsSequencing = true;
+ break;
+ }
+ }
+
+ if (!Frontier.SequencingStore || Frontier.SeenSequencingLoad ||
+ IsSequencing) {
+ // Sequence against the previous sequencing store
+ if (Frontier.SequencingStore)
+ Frontier.SequencingStore->addPredBarrier(SU);
+ // Sequence against all stores
+ for (auto &[V, SUs] : Frontier.Stores)
+ for (SUnit *S : SUs)
+ S->addPredBarrier(SU);
+ // Only drop loads who alias with the new sequencing store
+ for (auto &[V, SUs] : Frontier.Loads) {
+ for (auto It = SUs.begin(); It != SUs.end();) {
+ if (addChainDependency(SU, *It))
+ It = SUs.erase(It);
+ else
+ ++It;
+ }
+ }
+ // Update the sequencing store
+ Frontier.SequencingStore = SU;
+ Frontier.BaseObjects = std::move(Objs);
+ Frontier.SeenSequencingLoad = false;
+ // Clear maps
+ Frontier.Stores.clear();
+ } else {
+ // Always sequence against the sequencing store if there is one
+ Frontier.SequencingStore->addPredBarrier(SU);
+ // Add edges to potentially aliasing memops
+ addChainDependencies(SU, Frontier.Loads, UnknownValue);
+ addChainDependencies(SU, Frontier.Stores, UnknownValue);
+ // Join the frontier
+ Frontier.Stores.insert(SU, UnknownValue);
+ }
- // Map this store to 'UnknownValue'.
- Stores.insert(SU, UnknownValue);
+ addChainDependencies(SU, Loads);
+ addChainDependencies(SU, Stores);
} else {
// Add precise dependencies against all previously seen memory
// accesses mapped to the same Value(s).
- for (const UnderlyingObject &UnderlObj : Objs) {
- ValueType V = UnderlObj.getValue();
- bool ThisMayAlias = UnderlObj.mayAlias();
-
- // Add dependencies to previous stores and loads mapped to V.
- addChainDependencies(SU, (ThisMayAlias ? Stores : NonAliasStores), V);
- addChainDependencies(SU, (ThisMayAlias ? Loads : NonAliasLoads), V);
+ for (const ValueType V : Objs) {
+ // Add dependencies to previous loads and stores mapped to V.
+ addChainDependencies(SU, Loads, V);
+ addChainDependencies(SU, Stores, V);
}
// Update the store map after all chains have been added to avoid adding
// self-loop edge if multiple underlying objects are present.
- for (const UnderlyingObject &UnderlObj : Objs) {
- ValueType V = UnderlObj.getValue();
- bool ThisMayAlias = UnderlObj.mayAlias();
-
- // Map this store to V.
- (ThisMayAlias ? Stores : NonAliasStores).insert(SU, V);
- }
- // The store may have dependencies to unanalyzable loads and
- // stores.
- addChainDependencies(SU, Loads, UnknownValue);
- addChainDependencies(SU, Stores, UnknownValue);
+ for (const ValueType V : Objs)
+ Stores.insert(SU, V);
+
+ UnknownValueFrontier &Frontier =
+ Frontiers[0 /* TODO get address spaces for SU */];
+ // Always sequence against the sequencing store if there is one
+ if (Frontier.SequencingStore)
+ Frontier.SequencingStore->addPredBarrier(SU);
+ // Sequence against any relevant loads and stores in the frontier
+ addChainDependencies(SU, Frontier.Loads, UnknownValue);
+ addChainDependencies(SU, Frontier.Stores, UnknownValue);
}
} else { // SU is a load.
if (!ObjsFound) {
- // An unknown load depends on all stores.
- addChainDependencies(SU, Stores);
- addChainDependencies(SU, NonAliasStores);
+ UnknownValueFrontier &Frontier =
+ Frontiers[0 /* TODO get address spaces for SU */];
+ // Always sequence against the sequencing store if there is one
+ if (Frontier.SequencingStore)
+ Frontier.SequencingStore->addPredBarrier(SU);
+ // Add edges to potentially aliasing stores
+ addChainDependencies(SU, Frontier.Stores, UnknownValue);
+ // Join the frontier
+ Frontier.Loads.insert(SU, UnknownValue);
+
+ // If we load from a base object other than the sequencing objects, we
+ // become a sequencing load
+ for (const ValueType V : Objs) {
+ if (llvm::all_of(Frontier.BaseObjects,
+ [=](ValueType Base) { return Base != V; })) {
+ Frontier.SeenSequencingLoad = true;
+ break;
+ }
+ }
- Loads.insert(SU, UnknownValue);
+ addChainDependencies(SU, Stores);
} else {
- for (const UnderlyingObject &UnderlObj : Objs) {
- ValueType V = UnderlObj.getValue();
- bool ThisMayAlias = UnderlObj.mayAlias();
-
+ for (const ValueType V : Objs) {
// Add precise dependencies against all previously seen stores
- // mapping to the same Value(s).
- addChainDependencies(SU, (ThisMayAlias ? Stores : NonAliasStores), V);
+ // mapping to the sam Value(s).
----------------
SavchenkoValeriy wrote:
nit: same
https://github.com/llvm/llvm-project/pull/205689
More information about the llvm-commits
mailing list