@@ -4,41 +4,44 @@ import tip.ast._
44import tip .cfg ._
55import tip .lattices ._
66import tip .solvers ._
7+ import tip .ast .AstNodeData .{AstNodeWithDeclaration , DeclarationData }
78
89import scala .collection .mutable
9- import tip .ast .AstNodeData .{AstNodeWithDeclaration , DeclarationData }
1010
1111/**
1212 * Micro-transfer-functions for copy-constant-propagation analysis.
1313 */
1414trait CopyConstantPropagationAnalysisFunctions extends IDEAnalysis [ADeclaration , FlatLattice [Int ]] {
1515
16+ NoPointers .assertContainsProgram(cfg.prog)
17+ NoRecords .assertContainsProgram(cfg.prog)
18+
1619 implicit val declData : DeclarationData
1720
18- lazy val valuelattice = new FlatLattice [Int ]()
21+ val valuelattice = new FlatLattice [Int ]()
1922
20- lazy val edgelattice : EdgeLattice [valuelattice.type ] = new EdgeLattice (valuelattice)
23+ val edgelattice : EdgeFunctionLattice [valuelattice.type ] = new EdgeFunctionLattice (valuelattice)
2124
2225 import cfg ._
23- import edgelattice .{ ConstEdge , Edge , IdEdge }
24- import edgelattice .valuelattice .{ FlatEl , Top }
26+ import edgelattice ._
27+ import edgelattice .valuelattice ._
2528
26- def edgesCallToEntry (d : DL , call : CfgCallNode , entry : CfgFunEntryNode ): List [(DL , edgelattice.Edge )] =
27- entry.data.params.zip(call.invocation.args).foldLeft(List [(DL , edgelattice.Edge )]()) {
29+ def edgesCallToEntry (d : DL , call : CfgCallNode , entry : CfgFunEntryNode ): List [(DL , edgelattice.EdgeFunction )] =
30+ entry.data.params.zip(call.invocation.args).foldLeft(List [(DL , edgelattice.EdgeFunction )]()) {
2831 case (acc, (id, exp)) =>
2932 acc ++ assign(d, id, exp)
3033 }
3134
32- def edgesExitToAfterCall (d : DL , exit : CfgFunExitNode , aftercall : CfgAfterCallNode ): List [(DL , edgelattice.Edge )] =
35+ def edgesExitToAfterCall (d : DL , exit : CfgFunExitNode , aftercall : CfgAfterCallNode ): List [(DL , edgelattice.EdgeFunction )] =
3336 assign(d, aftercall.targetIdentifier.declaration, AstOps .returnId)
3437
35- def edgesCallToAfterCall (d2 : DL , call : CfgCallNode , aftercall : CfgAfterCallNode ): List [(DL , edgelattice.Edge )] =
38+ def edgesCallToAfterCall (d2 : DL , call : CfgCallNode , aftercall : CfgAfterCallNode ): List [(DL , edgelattice.EdgeFunction )] =
3639 d2 match {
3740 case Right (_) => List ((d2, IdEdge ()))
3841 case Left (a) => if (a == aftercall.targetIdentifier.declaration) List () else List ((d2, IdEdge ()))
3942 }
4043
41- def edgesOther (d : DL , n : CfgNode ): List [(DL , edgelattice.Edge )] =
44+ def edgesOther (d : DL , n : CfgNode ): List [(DL , edgelattice.EdgeFunction )] =
4245 n match {
4346 case r : CfgStmtNode =>
4447 r.data match {
@@ -47,7 +50,7 @@ trait CopyConstantPropagationAnalysisFunctions extends IDEAnalysis[ADeclaration,
4750 case varr : AVarStmt =>
4851 d match {
4952 case Right (_) =>
50- varr.declIds.foldLeft(List ((d, IdEdge ())): List [(DL , Edge )]) { (ps, id) => // identity edge from lambda to lambda
53+ varr.declIds.foldLeft(List ((d, IdEdge ())): List [(DL , EdgeFunction )]) { (ps, id) => // identity edge from lambda to lambda
5154 ps :+ (Left (id), ConstEdge (Top )) // top edge from lambda to each variable being declared
5255 }
5356 case Left (a) =>
@@ -84,8 +87,8 @@ trait CopyConstantPropagationAnalysisFunctions extends IDEAnalysis[ADeclaration,
8487 /**
8588 * Micro-transfer-functions for assigning an expression to an identifier.
8689 */
87- private def assign (d : DL , id : ADeclaration , exp : AExprOrIdentifierDeclaration ): List [(DL , edgelattice.Edge )] = {
88- val edges = mutable.ListBuffer [(DL , Edge )]()
90+ private def assign (d : DL , id : ADeclaration , exp : AExprOrIdentifierDeclaration ): List [(DL , edgelattice.EdgeFunction )] = {
91+ val edges = mutable.ListBuffer [(DL , EdgeFunction )]()
8992 d match {
9093 case Right (_) =>
9194 edges += ((d, IdEdge ())) // identity edge from lambda to lambda
@@ -116,22 +119,6 @@ trait CopyConstantPropagationAnalysisFunctions extends IDEAnalysis[ADeclaration,
116119/**
117120 * Copy-constant-propagation analysis using IDE solver.
118121 */
119- class CopyConstantPropagationIDEAnalysis (val cfg : InterproceduralProgramCfg )(implicit val declData : DeclarationData )
120- extends FlowSensitiveAnalysis [CfgNode ](cfg) {
121-
122- import tip .cfg .CfgOps ._
123-
124- val phase1 = new IDEPhase1Analysis [ADeclaration , FlatLattice [Int ]](cfg) with CopyConstantPropagationAnalysisFunctions
125- val phase2 = new IDEPhase2Analysis [ADeclaration , FlatLattice [Int ]](cfg, phase1) with CopyConstantPropagationAnalysisFunctions
126-
127- val declaredVars : Set [ADeclaration ] = domain.flatMap(_.declaredVarsAndParams)
128-
129- val lattice : MapLattice [CfgNode , MapLattice [ADeclaration , FlatLattice [Int ]]] = phase2.restructedlattice
130-
131- def analyze (): lattice.Element = {
132- FixpointSolvers .log.verb(s " IDE phase 1 " )
133- phase1.analyze()
134- FixpointSolvers .log.verb(s " IDE phase 2 " )
135- phase2.restructure(phase2.analyze()).asInstanceOf [lattice.Element ] // FIXME: avoid this asInstanceOf
136- }
137- }
122+ class CopyConstantPropagationIDEAnalysis (cfg : InterproceduralProgramCfg )(implicit val declData : DeclarationData )
123+ extends IDESolver [ADeclaration , FlatLattice [Int ]](cfg)
124+ with CopyConstantPropagationAnalysisFunctions
0 commit comments