From 22a7c561082bfea7edd4e070b6c8142fd31405dc Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 4 Jun 2018 16:21:00 -0700 Subject: [PATCH] Use `Context::for_function` to simplify the code. --- lib/filetests/src/test_compile.rs | 5 +---- lib/filetests/src/test_dce.rs | 4 +--- lib/filetests/src/test_legalizer.rs | 3 +-- lib/filetests/src/test_licm.rs | 4 +--- lib/filetests/src/test_postopt.rs | 4 +--- lib/filetests/src/test_preopt.rs | 4 +--- lib/filetests/src/test_regalloc.rs | 5 +---- lib/filetests/src/test_simple_gvn.rs | 4 +--- 8 files changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/filetests/src/test_compile.rs b/lib/filetests/src/test_compile.rs index ac326cb762..8cb26b4f1f 100644 --- a/lib/filetests/src/test_compile.rs +++ b/lib/filetests/src/test_compile.rs @@ -36,10 +36,7 @@ impl SubTest for TestCompile { fn run(&self, func: Cow, context: &Context) -> Result<()> { let isa = context.isa.expect("compile needs an ISA"); - - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); let code_size = comp_ctx .compile(isa) diff --git a/lib/filetests/src/test_dce.rs b/lib/filetests/src/test_dce.rs index 741ca1aac5..38e2b907a9 100644 --- a/lib/filetests/src/test_dce.rs +++ b/lib/filetests/src/test_dce.rs @@ -34,9 +34,7 @@ impl SubTest for TestDCE { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); comp_ctx.flowgraph(); comp_ctx.compute_loop_analysis(); diff --git a/lib/filetests/src/test_legalizer.rs b/lib/filetests/src/test_legalizer.rs index c3d84861ab..8ce1cffb1b 100644 --- a/lib/filetests/src/test_legalizer.rs +++ b/lib/filetests/src/test_legalizer.rs @@ -36,8 +36,7 @@ impl SubTest for TestLegalizer { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); let isa = context.isa.expect("legalizer needs an ISA"); comp_ctx.compute_cfg(); diff --git a/lib/filetests/src/test_licm.rs b/lib/filetests/src/test_licm.rs index e3d6812f91..2dda7b976b 100644 --- a/lib/filetests/src/test_licm.rs +++ b/lib/filetests/src/test_licm.rs @@ -34,9 +34,7 @@ impl SubTest for TestLICM { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); comp_ctx.flowgraph(); comp_ctx.compute_loop_analysis(); diff --git a/lib/filetests/src/test_postopt.rs b/lib/filetests/src/test_postopt.rs index 192a89c8b3..72bc3dfc2f 100644 --- a/lib/filetests/src/test_postopt.rs +++ b/lib/filetests/src/test_postopt.rs @@ -31,9 +31,7 @@ impl SubTest for TestPostopt { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); let isa = context.isa.expect("postopt needs an ISA"); comp_ctx.flowgraph(); diff --git a/lib/filetests/src/test_preopt.rs b/lib/filetests/src/test_preopt.rs index dbd68e8bac..1a3131ba83 100644 --- a/lib/filetests/src/test_preopt.rs +++ b/lib/filetests/src/test_preopt.rs @@ -31,9 +31,7 @@ impl SubTest for TestPreopt { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); let isa = context.isa.expect("preopt needs an ISA"); comp_ctx.flowgraph(); diff --git a/lib/filetests/src/test_regalloc.rs b/lib/filetests/src/test_regalloc.rs index 91217899e1..c74662c19a 100644 --- a/lib/filetests/src/test_regalloc.rs +++ b/lib/filetests/src/test_regalloc.rs @@ -39,10 +39,7 @@ impl SubTest for TestRegalloc { fn run(&self, func: Cow, context: &Context) -> Result<()> { let isa = context.isa.expect("register allocator needs an ISA"); - - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); comp_ctx.compute_cfg(); // TODO: Should we have an option to skip legalization? diff --git a/lib/filetests/src/test_simple_gvn.rs b/lib/filetests/src/test_simple_gvn.rs index 2036301bcc..7def78e95a 100644 --- a/lib/filetests/src/test_simple_gvn.rs +++ b/lib/filetests/src/test_simple_gvn.rs @@ -34,9 +34,7 @@ impl SubTest for TestSimpleGVN { } fn run(&self, func: Cow, context: &Context) -> Result<()> { - // Create a compilation context, and drop in the function. - let mut comp_ctx = cretonne_codegen::Context::new(); - comp_ctx.func = func.into_owned(); + let mut comp_ctx = cretonne_codegen::Context::for_function(func.into_owned()); comp_ctx.flowgraph(); comp_ctx