/// <summary> /// Builds a strongly connected component corresponding to: /// a1 = 0 /// a2 = phi(a1, a3) /// while (a2 != 10) /// { /// a3 = a2 + 4 /// } /// </summary> private List <SsaIdentifier> BuildScc() { var m = new ProcedureBuilder("test"); Identifier a = new Identifier("a", PrimitiveType.Word32, null); m.Label("b1"); m.Assign(a, Constant.Word32(0)); m.Label("b2"); m.Assign(a, m.IAdd(a, 4)); m.BranchIf(m.Ne(a, 10), "b2"); m.Label("b3"); m.Return(); this.dom = m.Procedure.CreateBlockDominatorGraph(); var ssa = new SsaTransform( new ProgramDataFlow(), m.Procedure, null, dom, new HashSet <RegisterStorage>()); /* * * proc = new Procedure("test", new Frame(PrimitiveType.Word32)); * Block b1 = proc.AddBlock("b1"); * Block b2 = proc.AddBlock("b2"); * * Identifier a2 = new Identifier("a2", PrimitiveType.Word32, null); * Identifier a3 = new Identifier("a3", PrimitiveType.Word32, null); * PhiFunction phi = new PhiFunction(a1.DataType, new Expression [] { a1, a3 }); * * Statement stm_a1 = new Statement(0, new Assignment(a1, Constant.Word32(0)), null); * Statement stm_a2 = new Statement(0, new PhiAssignment(a2, new PhiFunction(a1.DataType, a1, a3 )), null); * Statement stm_ex = new Statement(0, new Branch(new BinaryExpression(Operator.Ne, PrimitiveType.Bool, a2, Constant.Word32(10)), b2), null); * Statement stm_a3 = new Statement(0, new Assignment(a3, new BinaryExpression(Operator.IAdd, a3.DataType, a2, Constant.Word32(4))), null); * b1.Statements.Add(stm_a1); * * b2.Statements.Add(stm_a2); * b2.Statements.Add(stm_a3); * * SsaIdentifier sid_a1 = new SsaIdentifier(a1, a1, stm_a1, ((Assignment)stm_a1.Instruction).Src, false); * SsaIdentifier sid_a2 = new SsaIdentifier(a2, a2, stm_a2, ((PhiAssignment) stm_a2.Instruction).Src, false); * SsaIdentifier sid_a3 = new SsaIdentifier(a3, a3, stm_a3, ((Assignment) stm_a3.Instruction).Src, false); * sid_a1.Uses.Add(stm_a2); * ssaIds = new SsaIdentifierCollection(); * ssaIds.Add(a1, sid_a1); * ssaIds.Add(a2, sid_a2); * ssaIds.Add(a3, sid_a3); */ ssaIds = ssa.SsaState.Identifiers; List <SsaIdentifier> list = new List <SsaIdentifier> { ssaIds.Where(i => i.Identifier.Name == "a_0").Single(), ssaIds.Where(i => i.Identifier.Name == "a_1").Single(), ssaIds.Where(i => i.Identifier.Name == "a_2").Single(), }; return(list); }
public void Liv_FindFinalValue() { Prepare(new ByteArrayLoopMock().Procedure); var liv = new LinearInductionVariableFinder(proc, ssaIds, null); var a = new List <SsaIdentifier>(); a.Add(ssaIds.Where(s => s.Identifier.Name == "i_1").Single()); a.Add(ssaIds.Where(s => s.Identifier.Name == "i_4").Single()); Constant c = liv.FindFinalValue(a); Assert.AreEqual(10, c.ToInt32()); Assert.AreEqual("branch i_1 < 0x0000000A body", liv.Context.TestStatement.ToString()); }
public void DeciWeb() { Build(new DiamondMock().Procedure); DeclarationInserter deci = new DeclarationInserter(ssaIds, doms); Web web = new Web(); SsaIdentifier r_1 = ssaIds.Where(s => s.Identifier.Name == "r_1").Single(); SsaIdentifier r_3 = ssaIds.Where(s => s.Identifier.Name == "r_3").Single(); SsaIdentifier r_4 = ssaIds.Where(s => s.Identifier.Name == "r_4").Single(); web.Add(r_1); web.Add(r_3); web.Add(r_4); deci.InsertDeclaration(web); Assert.AreEqual("word32 r_1", proc.ControlGraph.Blocks[2].Statements[0].Instruction.ToString()); }
public void LciLiveAtLoop() { Build(new LiveLoopMock().Procedure, new FakeArchitecture()); var lci = new LiveCopyInserter(proc, ssaIds); var i = ssaIds.Where(s => s.Identifier.Name == "i").Single().Identifier; var i_3 = ssaIds.Where(s => s.Identifier.Name == "i_3").Single().Identifier; var loopHdr = proc.ControlGraph.Blocks[2]; Assert.IsFalse(lci.IsLiveAtCopyPoint(i, loopHdr)); Assert.IsTrue(lci.IsLiveAtCopyPoint(i_3, loopHdr), "i_3 should be live"); }
/// <summary> /// Builds a strongly connected component corresponding to: /// a1 = 0 /// a2 = phi(a1, a3) /// while (a2 != 10) /// { /// a3 = a2 + 4 /// } /// </summary> private List<SsaIdentifier> BuildScc() { var m = new ProcedureBuilder("test"); Identifier a = new Identifier("a", PrimitiveType.Word32, null); m.Label("b1"); m.Assign(a, Constant.Word32(0)); m.Label("b2"); m.Assign(a, m.IAdd(a, 4)); m.BranchIf(m.Ne(a, 10), "b2"); m.Label("b3"); m.Return(); this.dom = m.Procedure.CreateBlockDominatorGraph(); var ssa = new SsaTransform(new ProgramDataFlow(), m.Procedure, dom); /* proc = new Procedure("test", new Frame(PrimitiveType.Word32)); Block b1 = proc.AddBlock("b1"); Block b2 = proc.AddBlock("b2"); Identifier a2 = new Identifier("a2", PrimitiveType.Word32, null); Identifier a3 = new Identifier("a3", PrimitiveType.Word32, null); PhiFunction phi = new PhiFunction(a1.DataType, new Expression [] { a1, a3 }); Statement stm_a1 = new Statement(0, new Assignment(a1, Constant.Word32(0)), null); Statement stm_a2 = new Statement(0, new PhiAssignment(a2, new PhiFunction(a1.DataType, a1, a3 )), null); Statement stm_ex = new Statement(0, new Branch(new BinaryExpression(Operator.Ne, PrimitiveType.Bool, a2, Constant.Word32(10)), b2), null); Statement stm_a3 = new Statement(0, new Assignment(a3, new BinaryExpression(Operator.IAdd, a3.DataType, a2, Constant.Word32(4))), null); b1.Statements.Add(stm_a1); b2.Statements.Add(stm_a2); b2.Statements.Add(stm_a3); SsaIdentifier sid_a1 = new SsaIdentifier(a1, a1, stm_a1, ((Assignment)stm_a1.Instruction).Src, false); SsaIdentifier sid_a2 = new SsaIdentifier(a2, a2, stm_a2, ((PhiAssignment) stm_a2.Instruction).Src, false); SsaIdentifier sid_a3 = new SsaIdentifier(a3, a3, stm_a3, ((Assignment) stm_a3.Instruction).Src, false); sid_a1.Uses.Add(stm_a2); ssaIds = new SsaIdentifierCollection(); ssaIds.Add(a1, sid_a1); ssaIds.Add(a2, sid_a2); ssaIds.Add(a3, sid_a3); */ ssaIds = ssa.SsaState.Identifiers; List<SsaIdentifier> list = new List<SsaIdentifier> { ssaIds.Where(i => i.Identifier.Name == "a_0").Single(), ssaIds.Where(i => i.Identifier.Name == "a_1").Single(), ssaIds.Where(i => i.Identifier.Name == "a_2").Single(), }; return list; }