@samitouri / QOS-React-2 / commits / a574d15985

[Fix] Control Dep Should Only Add To Defs

Control dep should only affect how things are invalidated, which are modeled as defs including declarations, writable uses to variables and expressions. Closes #633 commit-id:41bd6fe5

Xuan Huang (黄玄) committed Oct 5, 2022 at 18:42 UTC a574d15985fbdc184e7e3328fe4d528472c843ae
2 files changed +20 -6
compiler/forget/src/IR/FuncTopLevel.ts
+14 -4
@@ -77,7 +77,10 @@ export class FuncTopLevel {
77 }
78
79 /**
80 - * All "uses" of {@link Val}.
80 + * All usages.
81 + * - all references to declarations, regardless of the ref kind.
82 + * - all references to expressions.
83 + * - all references to free variables (behind a flag).
84 */
85 get uses(): Ref<Val>[] {
86 return [
@@ -88,16 +91,23 @@ export class FuncTopLevel {
91 }
92
93 /**
91 - * All mutable uses. This needs to be lazy so it's computed after refinements.
94 + * All usages that are considered potentially mutable (not readonly).
95 */
96 get mutableUses(): Ref<Val>[] {
97 return this.uses.filter((use) => !use.immutable);
98 }
99
100 /**
98 - * All defs. This needs to be lazy since it depends on {@link mutableUses}.
101 + * All "defs".
102 + * - all declarations
103 + * - all expressions (yea they are immediately defined and referenced)
104 + * - all mutable uses
105 */
106 get defs(): Val[] {
101 - return [...this.decls, ...this.mutableUses.map((use) => use.val)];
107 + return [
108 + ...this.decls,
109 + ...this.refsToExprs.map((use) => use.val),
110 + ...this.mutableUses.map((use) => use.val),
111 + ];
112 }
113 }
compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts
+6 -2
@@ -132,8 +132,12 @@ function populateValGraph(valGraph: DepGraph.ValGraph, irFunc: IR.Func) {
132 const basicBlock = cfg.blocks.get(blockId)!;
133 basicBlock.parents.forEach((parent) => {
134 for (const dep of controlDeps) {
135 - for (const use of parent.uses) {
136 - valGraph.getOrCreateVertex(use.val).addDependency(dep);
135 + for (const val of parent.defs) {
136 + invariant(
137 + !IR.isInputVal(val),
138 + "No inputs should be control dependent."
139 + );
140 + valGraph.getOrCreateVertex(val).addDependency(dep);
141 }
142 }
143 });