This class is used to compute value numbers of all the SSA variables of a procedure. As a useful side effect, it also detects induction variables, determines their stride &c. This will be useful later when we need to classify arrays.
Exemple #1
0
		//[Test]
		public void VnSumTest()
		{
			Program prog = RewriteCodeFragment(
				@".i86
	push bp
	mov	 bp,sp
	mov	dx,3
	add dx,dx

	mov bx,3
	lea dx,[bx+3]
	mov sp,bp
	pop	bp
	ret
	");
			using (FileUnitTester fut = new FileUnitTester("Analysis/VnSumTest.txt"))
			{
				Procedure proc = prog.Procedures.Values[0];
				Aliases alias = new Aliases(proc, prog.Architecture);
				alias.Transform();
				var gr = proc.CreateBlockDominatorGraph();
                SsaTransform sst = new SsaTransform(
                    new ProgramDataFlow(), 
                    proc,
                    null,
                    gr,
                    new HashSet<RegisterStorage>());
				SsaState ssa = sst.SsaState;
				ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
				DumpProc(proc, ssa, fut.TextWriter);
				vn.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Exemple #2
0
        //[Test]
        public void VnLoop()
        {
            Program program = RewriteCodeFragment(@".i86
            push ax
            jmp looptest
            again:
            mov si,[0x302]
            mov ax,[si+04]
            add [si+06],ax
            looptest:
            cmp	ax,bx
            jl again

            pop ax
            ret
            ");
            using (FileUnitTester fut = new FileUnitTester("Analysis/VnLoop.txt"))
            {
                Procedure proc = program.Procedures.Values[0];
                var gr = proc.CreateBlockDominatorGraph();
                Aliases alias = new Aliases(proc, program.Architecture);
                alias.Transform();
                SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
                SsaState ssa = sst.SsaState;
                DumpProc(proc, ssa, fut.TextWriter);
                ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
                vn.Write(fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Exemple #3
0
        //[Test]
        public void VnLoopTest()
        {
            Program program = this.RewriteCodeFragment(
                @".i86
            mov	ax,1
            mov	bx,1
            isdone:
            cmp	ax,10
            jz  done

            inc ax
            inc bx
            jmp isdone
            done:
            mov [0002],ax
            mov	[0004],bx
            ret
            ");
            using (FileUnitTester fut = new FileUnitTester("Analysis/VnLoopTest.txt"))
            {
                Procedure proc = program.Procedures.Values[0];
                var gr = proc.CreateBlockDominatorGraph();
                Aliases alias = new Aliases(proc, program.Architecture);
                alias.Transform();
                SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
                SsaState ssa = sst.SsaState;
                DumpProc(proc, ssa, fut.TextWriter);

                DeadCode.Eliminate(proc, ssa);

                DumpProc(proc, ssa, fut.TextWriter);

                ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
                vn.Write(fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Exemple #4
0
 protected override void RunTest(Program program, TextWriter writer)
 {
     var progFlow = new ProgramDataFlow();
     foreach (Procedure proc in program.Procedures.Values)
     {
         var gr = proc.CreateBlockDominatorGraph();
         Aliases alias = new Aliases(proc, program.Architecture);
         alias.Transform();
         SsaTransform sst = new SsaTransform(progFlow, proc, gr);
         SsaState ssa = sst.SsaState;
         DumpProc(proc, ssa, writer);
         ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
         vn.Write(writer);
         writer.WriteLine();
     }
 }
Exemple #5
0
        //[Test]
        public void VnRedundantStore()
        {
            Program program = RewriteCodeFragment(
                @".i86
            mov	ax,2
            isdone:
            cmp	bx,10
            jz  yay
            boo: mov ax,3
            jmp done
            yay:
            mov ax,3
            done:
            ret
            ");
            using (FileUnitTester fut = new FileUnitTester("Analysis/VnRedundantStore.txt"))
            {
                Procedure proc = program.Procedures.Values[0];
                var gr = proc.CreateBlockDominatorGraph();
                Aliases alias = new Aliases(proc, program.Architecture);
                alias.Transform();
                SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
                SsaState ssa = sst.SsaState;
                DumpProc(proc, ssa, fut.TextWriter);
                ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
                vn.Write(fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Exemple #6
0
 //[Test]
 public void VnMemoryTest()
 {
     Program program = RewriteCodeFragment(
         @".i86
     mov word ptr [bx+2],0
     mov si,[bx+4]
     mov ax,[bx+2]
     mov cx,[bx+2]
     mov dx,[bx+4]
     ret
     ");
     using (FileUnitTester fut = new FileUnitTester("Analysis/VnMemoryTest.txt"))
     {
         Procedure proc = program.Procedures.Values[0];
         var gr = proc.CreateBlockDominatorGraph();
         Aliases alias = new Aliases(proc, program.Architecture);
         alias.Transform();
         SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
         SsaState ssa = sst.SsaState;
         ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
         DumpProc(proc, ssa, fut.TextWriter);
         vn.Write(fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Exemple #7
0
 public NodeVisitor(ValueNumbering vn)
 {
     this.vn     = vn;
     this.ssaIds = vn.ssaIds;
     this.nodes  = vn.nodes;
 }
Exemple #8
0
			public NodeVisitor(ValueNumbering vn)
			{
				this.vn = vn;
				this.ssaIds = vn.ssaIds;
				this.nodes = vn.nodes;
			}