From a574d15985fbdc184e7e3328fe4d528472c843ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xuan=20Huang=20=28=E9=BB=84=E7=8E=84=29?= Date: Wed, 5 Oct 2022 18:42:11 -0400 Subject: [PATCH] [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 --- compiler/forget/src/IR/FuncTopLevel.ts | 18 ++++++++++++++---- .../forget/src/MiddleEnd/DepGraphAnalysis.ts | 8 ++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler/forget/src/IR/FuncTopLevel.ts b/compiler/forget/src/IR/FuncTopLevel.ts index c4c70488cb..59aa8f1dcb 100644 --- a/compiler/forget/src/IR/FuncTopLevel.ts +++ b/compiler/forget/src/IR/FuncTopLevel.ts @@ -77,7 +77,10 @@ export class FuncTopLevel { } /** - * All "uses" of {@link Val}. + * All usages. + * - all references to declarations, regardless of the ref kind. + * - all references to expressions. + * - all references to free variables (behind a flag). */ get uses(): Ref[] { return [ @@ -88,16 +91,23 @@ export class FuncTopLevel { } /** - * All mutable uses. This needs to be lazy so it's computed after refinements. + * All usages that are considered potentially mutable (not readonly). */ get mutableUses(): Ref[] { return this.uses.filter((use) => !use.immutable); } /** - * All defs. This needs to be lazy since it depends on {@link mutableUses}. + * All "defs". + * - all declarations + * - all expressions (yea they are immediately defined and referenced) + * - all mutable uses */ get defs(): Val[] { - return [...this.decls, ...this.mutableUses.map((use) => use.val)]; + return [ + ...this.decls, + ...this.refsToExprs.map((use) => use.val), + ...this.mutableUses.map((use) => use.val), + ]; } } diff --git a/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts b/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts index 08d406782b..7eba0daa25 100644 --- a/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts +++ b/compiler/forget/src/MiddleEnd/DepGraphAnalysis.ts @@ -132,8 +132,12 @@ function populateValGraph(valGraph: DepGraph.ValGraph, irFunc: IR.Func) { const basicBlock = cfg.blocks.get(blockId)!; basicBlock.parents.forEach((parent) => { for (const dep of controlDeps) { - for (const use of parent.uses) { - valGraph.getOrCreateVertex(use.val).addDependency(dep); + for (const val of parent.defs) { + invariant( + !IR.isInputVal(val), + "No inputs should be control dependent." + ); + valGraph.getOrCreateVertex(val).addDependency(dep); } } });