Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay loading of AliasAnalysis data #10837

Merged
merged 42 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
233c046
Add stub of FramePointerAnalysis pass
Akirathan Jul 31, 2024
71bc55d
Add stub of FramePointerAnalysisTest
Akirathan Jul 31, 2024
56e7b3f
Add more framepointer tests
Akirathan Aug 1, 2024
1218406
FramePointer has constructor for better debugging
Akirathan Aug 1, 2024
7125220
Update tests - FramePointer metadata is also in Info.Def
Akirathan Aug 1, 2024
05610fa
FramePointerAnalysis traverses the whole IR.
Akirathan Aug 2, 2024
c66b25f
Fix test - check for metadata
Akirathan Aug 2, 2024
3520614
Reorder methods in FramePointerAnalysis
Akirathan Aug 2, 2024
e8c821a
Fix argument processing
Akirathan Aug 2, 2024
d91c580
Improve some toString methods for debugging
Akirathan Aug 2, 2024
65e8c1a
Fix parent levels in tests
Akirathan Aug 2, 2024
61821bf
FramePointerAnalysis does not copy IRs
Akirathan Aug 6, 2024
1f373f1
FramePointerAnalysis metadata is Persistable
Akirathan Aug 6, 2024
98356a6
FramePointerAnalysis attaches metadata to atom constructors
Akirathan Aug 6, 2024
d274cbb
Synthetic self argument is handled specially
Akirathan Aug 6, 2024
7495dd7
Merge branch 'develop' into wip/akirathan/10129-cache-frame-pointer
Akirathan Aug 7, 2024
dae42c3
IRDumperPass is run as the last compiler pass
Akirathan Aug 7, 2024
3fdec42
IRDumper can dump alias analysis metadata
Akirathan Aug 7, 2024
4427f6f
FramePointerMeta has meaningful toString
Akirathan Aug 7, 2024
dd484cc
FramePointerAnalysis process case expressions
Akirathan Aug 7, 2024
db7b645
Fix javadoc links
Akirathan Aug 12, 2024
6c2aadf
FramePointer is attached to GenericAnnotation expression
Akirathan Aug 12, 2024
9da19fe
IRDumper handles case type patterns
Akirathan Aug 12, 2024
10b0410
FramePointer is attached to argument default value expressions
Akirathan Aug 12, 2024
a46c3b7
Add test for default argument value metadata
Akirathan Aug 13, 2024
cc211f9
Attach frame pointer to default value expressions even if they have n…
Akirathan Aug 13, 2024
db92068
FramePointerAnalysis can run inline on expression
Akirathan Aug 13, 2024
056f029
Merge branch 'develop' into wip/akirathan/10129-cache-frame-pointer
Akirathan Aug 13, 2024
ce74f86
Fixes after rebase
Akirathan Aug 13, 2024
9e25171
Fix annotation processing
Akirathan Aug 14, 2024
f01eef0
Add tests for no frame pointers on global symbol usages
Akirathan Aug 14, 2024
af1b7e8
Do not use AliasAnalysis in IrToTruffle.
Akirathan Aug 14, 2024
9f4e71f
Remove unused methods from LocalScope
Akirathan Aug 14, 2024
b5f809f
Remove unused import
Akirathan Aug 14, 2024
c32dc5f
fmt
Akirathan Aug 14, 2024
e08f77a
Fix scala.MatchError for case patterns
Akirathan Aug 15, 2024
f52fe9b
Do not use absolute code locations in the test.
Akirathan Aug 15, 2024
c8faf9f
Delay AliasAnalysis instantiation
JaroslavTulach Aug 16, 2024
a487d91
Resolve merge conflicts with origin/develop
JaroslavTulach Aug 16, 2024
3283747
scope() is a Function0
JaroslavTulach Aug 17, 2024
32344c1
Using provider and lazy val to guarantee idempotent results
JaroslavTulach Aug 17, 2024
38bc732
LocalScope.root cannot be a singleton
JaroslavTulach Aug 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ import scala.jdk.CollectionConverters._
*/
class LocalScope(
final val parentScope: Option[LocalScope],
final val aliasingGraph: AliasGraph,
final val scope: AliasGraph.Scope,
final val dataflowInfo: DataflowAnalysis.Metadata,
final val aliasingGraph: () => AliasGraph,
final private val scopeProvider: () => AliasGraph.Scope,
final private val dataflowInfoProvider: () => DataflowAnalysis.Metadata,
final val flattenToParent: Boolean = false,
private val parentFrameSlotIdxs: Map[AliasGraph.Id, Int] = Map()
) {
lazy val scope: AliasGraph.Scope = scopeProvider()
lazy val dataflowInfo: DataflowAnalysis.Metadata = dataflowInfoProvider()

private lazy val localFrameSlotIdxs: Map[AliasGraph.Id, Int] =
gatherLocalFrameSlotIdxs()

Expand All @@ -50,7 +53,7 @@ class LocalScope(
*
* @return a child of this scope
*/
def createChild(): LocalScope = createChild(scope.addChild())
def createChild(): LocalScope = createChild(() => scope.addChild())

/** Creates a child using a known aliasing scope.
*
Expand All @@ -60,14 +63,14 @@ class LocalScope(
* @return a child of this scope
*/
def createChild(
childScope: AliasGraph.Scope,
childScope: () => AliasGraph.Scope,
flattenToParent: Boolean = false
): LocalScope = {
new LocalScope(
Some(this),
aliasingGraph,
childScope,
dataflowInfo,
() => dataflowInfo,
flattenToParent,
allFrameSlotIdxs
)
Expand Down Expand Up @@ -128,11 +131,12 @@ object LocalScope {
*/
def root: LocalScope = {
val graph = new AliasGraph
val info = DataflowAnalysis.DependencyInfo()
new LocalScope(
None,
graph,
graph.rootScope,
DataflowAnalysis.DependencyInfo()
() => graph,
() => graph.rootScope,
() => info
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ case object AliasAnalysis extends IRPass {
.deepCopy(mutable.Map())
.withParent(localScope.scope)

val ag = localScope.aliasingGraph()
val graph =
if (shouldWriteState) localScope.aliasingGraph
if (shouldWriteState) ag
else {
val mapping = mutable.Map(localScope.scope -> scope)
localScope.aliasingGraph.deepCopy(mapping)
ag.deepCopy(mapping)
}
val result = analyseExpression(ir, graph, scope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ case object FramePointerAnalysis extends IRPass {
"Local scope must be provided for frame pointer analysis"
)
case Some(localScope) =>
val graph = localScope.aliasingGraph
val graph = localScope.aliasingGraph()
processExpression(exprIr, graph)
exprIr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,23 @@ class IrToTruffle(
atomCons: AtomConstructor,
atomDefn: Definition.Data
): Unit = {
val scopeInfo = atomDefn
.unsafeGetMetadata(
AliasAnalysis,
"No root scope on an atom definition."
)
.unsafeAs[AliasMetadata.RootScope]
def scopeInfo() = {
atomDefn
.unsafeGetMetadata(
AliasAnalysis,
"No root scope on an atom definition."
)
.unsafeAs[AliasMetadata.RootScope]
}

val dataflowInfo = atomDefn.unsafeGetMetadata(
def dataflowInfo() = atomDefn.unsafeGetMetadata(
DataflowAnalysis,
"No dataflow information associated with an atom."
)
val localScope = new LocalScope(
None,
scopeInfo.graph,
scopeInfo.graph.rootScope,
() => scopeInfo().graph,
() => scopeInfo().graph.rootScope,
dataflowInfo
)

Expand Down Expand Up @@ -333,8 +335,8 @@ class IrToTruffle(
scopeElements.mkString(Constants.SCOPE_SEPARATOR)
val expressionProcessor = new ExpressionProcessor(
scopeName,
scopeInfo.graph,
scopeInfo.graph.rootScope,
() => scopeInfo().graph,
() => scopeInfo().graph.rootScope,
dataflowInfo,
atomDefn.name.name
)
Expand Down Expand Up @@ -373,14 +375,16 @@ class IrToTruffle(
}

methodDefs.foreach(methodDef => {
val scopeInfo = methodDef
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for method " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = methodDef.unsafeGetMetadata(
def scopeInfo() = {
methodDef
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for method " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasMetadata.RootScope]
}
def dataflowInfo() = methodDef.unsafeGetMetadata(
DataflowAnalysis,
"Method definition missing dataflow information."
)
Expand Down Expand Up @@ -414,8 +418,8 @@ class IrToTruffle(
cons.getName ++ Constants.SCOPE_SEPARATOR ++ methodDef.methodName.name
val expressionProcessor = new ExpressionProcessor(
fullMethodDefName,
scopeInfo.graph,
scopeInfo.graph.rootScope,
() => scopeInfo().graph,
() => scopeInfo().graph.rootScope,
dataflowInfo,
fullMethodDefName
)
Expand Down Expand Up @@ -548,16 +552,18 @@ class IrToTruffle(
)
val scopeName =
scopeElements.mkString(Constants.SCOPE_SEPARATOR)
val scopeInfo = annotation
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for annotation " +
s"${annotation.name} of method " +
scopeElements.init
.mkString(Constants.SCOPE_SEPARATOR)
)
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = annotation.unsafeGetMetadata(
def scopeInfo() = {
annotation
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for annotation " +
s"${annotation.name} of method " +
scopeElements.init
.mkString(Constants.SCOPE_SEPARATOR)
)
.unsafeAs[AliasMetadata.RootScope]
}
def dataflowInfo() = annotation.unsafeGetMetadata(
DataflowAnalysis,
"Missing dataflow information for annotation " +
s"${annotation.name} of method " +
Expand All @@ -566,8 +572,8 @@ class IrToTruffle(
)
val expressionProcessor = new ExpressionProcessor(
scopeName,
scopeInfo.graph,
scopeInfo.graph.rootScope,
() => scopeInfo().graph,
() => scopeInfo().graph.rootScope,
dataflowInfo,
methodDef.methodName.name
)
Expand Down Expand Up @@ -767,14 +773,16 @@ class IrToTruffle(

// Register the conversion definitions in scope
conversionDefs.foreach(methodDef => {
val scopeInfo = methodDef
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for conversion " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = methodDef.unsafeGetMetadata(
def scopeInfo() = {
methodDef
.unsafeGetMetadata(
AliasAnalysis,
s"Missing scope information for conversion " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasMetadata.RootScope]
}
def dataflowInfo() = methodDef.unsafeGetMetadata(
DataflowAnalysis,
"Method definition missing dataflow information."
)
Expand All @@ -790,8 +798,8 @@ class IrToTruffle(
toOpt.zip(fromOpt).foreach { case (toType, fromType) =>
val expressionProcessor = new ExpressionProcessor(
toType.getName ++ Constants.SCOPE_SEPARATOR ++ methodDef.methodName.name,
scopeInfo.graph,
scopeInfo.graph.rootScope,
() => scopeInfo().graph,
() => scopeInfo().graph.rootScope,
dataflowInfo,
methodDef.methodName.name
)
Expand Down Expand Up @@ -1225,9 +1233,9 @@ class IrToTruffle(
*/
def this(
scopeName: String,
graph: AliasGraph,
scope: AliasScope,
dataflowInfo: DataflowAnalysis.Metadata,
graph: () => AliasGraph,
scope: () => AliasScope,
dataflowInfo: () => DataflowAnalysis.Metadata,
initialName: String
) = {
this(
Expand All @@ -1246,7 +1254,7 @@ class IrToTruffle(
*/
def createChild(
name: String,
scope: AliasScope,
scope: () => AliasScope,
initialName: String
): ExpressionProcessor = {
new ExpressionProcessor(this.scope.createChild(scope), name, initialName)
Expand Down Expand Up @@ -1332,16 +1340,18 @@ class IrToTruffle(
*/
private def processBlock(block: Expression.Block): RuntimeExpression = {
if (block.suspended) {
val scopeInfo = block
.unsafeGetMetadata(
AliasAnalysis,
"Missing scope information on block."
)
.unsafeAs[AliasMetadata.ChildScope]
def scopeInfo() = {
block
.unsafeGetMetadata(
AliasAnalysis,
"Missing scope information on block."
)
.unsafeAs[AliasMetadata.ChildScope]
}

val childFactory = this.createChild(
"suspended-block",
scopeInfo.scope,
() => scopeInfo().scope,
"suspended " + currentVarName
)
val childScope = childFactory.scope
Expand Down Expand Up @@ -1446,17 +1456,19 @@ class IrToTruffle(
def processCaseBranch(
branch: Case.Branch
): Either[BadPatternMatch, BranchNode] = {
val scopeInfo = branch
.unsafeGetMetadata(
AliasAnalysis,
"No scope information on a case branch."
)
.unsafeAs[AliasMetadata.ChildScope]
def scopeInfo() = {
branch
.unsafeGetMetadata(
AliasAnalysis,
"No scope information on a case branch."
)
.unsafeAs[AliasMetadata.ChildScope]
}

val childProcessor =
this.createChild(
"case_branch",
scopeInfo.scope,
() => scopeInfo().scope,
"case " + currentVarName
)

Expand Down Expand Up @@ -1846,10 +1858,11 @@ class IrToTruffle(
function: Function,
binding: Boolean
): RuntimeExpression = {
val scopeInfo = function
.unsafeGetMetadata(AliasAnalysis, "No scope info on a function.")
.unsafeAs[AliasMetadata.ChildScope]

def scopeInfo() = {
function
.unsafeGetMetadata(AliasAnalysis, "No scope info on a function.")
.unsafeAs[AliasMetadata.ChildScope]
}
if (function.body.isInstanceOf[Function]) {
throw new CompilerError(
"Lambda found directly as function body. It looks like Lambda " +
Expand All @@ -1864,7 +1877,11 @@ class IrToTruffle(
}

val child =
this.createChild(scopeName, scopeInfo.scope, "case " + currentVarName)
this.createChild(
scopeName,
() => scopeInfo().scope,
"case " + currentVarName
)

val fn = child.processFunctionBody(
function.arguments,
Expand Down Expand Up @@ -2434,12 +2451,14 @@ class IrToTruffle(
_,
_
) =>
val scopeInfo = arg
.unsafeGetMetadata(
AliasAnalysis,
"No scope attached to a call argument."
)
.unsafeAs[AliasMetadata.ChildScope]
def scopeInfo() = {
arg
.unsafeGetMetadata(
AliasAnalysis,
"No scope attached to a call argument."
)
.unsafeAs[AliasMetadata.ChildScope]
}

def valueHasSomeTypeCheck() =
value.getMetadata(TypeSignatures).isDefined
Expand All @@ -2452,10 +2471,10 @@ class IrToTruffle(
}

val childScope = if (shouldCreateClosureRootNode) {
scope.createChild(scopeInfo.scope)
scope.createChild(() => scopeInfo().scope)
} else {
// Note [Scope Flattening]
scope.createChild(scopeInfo.scope, flattenToParent = true)
scope.createChild(() => scopeInfo().scope, flattenToParent = true)
}
val argumentExpression =
new ExpressionProcessor(childScope, scopeName, initialName)
Expand Down
Loading