public void ConstPropagation() { var program = @" var a, x, c; input(c); if c > 5 x = 10; else input(c); if c > 5 x = 20; a = x; "; var graph = GenCFG(program); var algorithm = new ConstantPropagation(); _ = algorithm.Execute(graph); var iterationsFast = algorithm.Iterations; _ = algorithm.Execute(graph, false); var iterationsSlow = algorithm.Iterations; Assert.LessOrEqual(iterationsFast, iterationsSlow); }
public void ConstPropagationIterative() { var cfg = GenCFG(@" var a, x, c; if c > 5 x = 10; else input(c); if c > 5 a = x; "); var constProp = new ConstantPropagation(); var result = constProp.Execute(cfg); var blocks = cfg.GetCurrentBasicBlocks(); var(_, Out) = result[blocks.Last()]; Assert.AreEqual(LatticeTypeData.NAC, Out["c"].Type); Assert.AreEqual(LatticeTypeData.CONST, Out["x"].Type); Assert.AreEqual(LatticeTypeData.CONST, Out["a"].Type); Assert.AreEqual("10", Out["x"].ConstValue); Assert.AreEqual("10", Out["a"].ConstValue); }