//[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, gr);
				SsaState ssa = sst.SsaState;
				ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
				DumpProc(proc, ssa, fut.TextWriter);
				vn.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
		//[Test]
		public void VnLoopTest()
		{
			Program prog = 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 = prog.Procedures.Values[0];
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.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();
			}
		}
		//[Test]
		public void VnMemoryTest()
		{
			Program prog = 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 = prog.Procedures.Values[0];
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.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();
			}
		}
		protected override void RunTest(Program prog, TextWriter writer)
		{
            var progFlow = new ProgramDataFlow();
			foreach (Procedure proc in prog.Procedures.Values)
			{
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.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();

			}
		}
		//[Test]
		public void VnLoop()
		{
			Program prog = 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 = prog.Procedures.Values[0];
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.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();
			}
		}
		//[Test]
		public void VnRedundantStore()
		{
			Program prog = 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 = prog.Procedures.Values[0];
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.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 #7
0
			public NodeVisitor(ValueNumbering vn)
			{
				this.vn = vn;
				this.ssaIds = vn.ssaIds;
				this.nodes = vn.nodes;
			}