Cranelift: remove non-egraphs optimization pipeline and use_egraphs option. (#6167)

* Cranelift: remove non-egraphs optimization pipeline and `use_egraphs` option.

This PR removes the LICM, GVN, and preopt passes, and associated support
pieces, from `cranelift-codegen`. Not to worry, we still have
optimizations: the egraph framework subsumes all of these, and has been
on by default since #5181.

A few decision points:

- Filetests for the legacy LICM, GVN and simple_preopt were removed too.
  As we built optimizations in the egraph framework we wrote new tests
  for the equivalent functionality, and many of the old tests were
  testing specific behaviors in the old implementations that may not be
  relevant anymore. However if folks prefer I could take a different
  approach here and try to port over all of the tests.

- The corresponding filetest modes (commands) were deleted too. The
  `test alias_analysis` mode remains, but no longer invokes a separate
  GVN first (since there is no separate GVN that will not also do alias
  analysis) so the tests were tweaked slightly to work with that. The
  egrpah testsuite also covers alias analysis.

- The `divconst_magic_numbers` module is removed since it's unused
  without `simple_preopt`, though this is the one remaining optimization
  we still need to build in the egraphs framework, pending #5908. The
  magic numbers will live forever in git history so removing this in the
  meantime is not a major issue IMHO.

- The `use_egraphs` setting itself was removed at both the Cranelift and
  Wasmtime levels. It has been marked deprecated for a few releases now
  (Wasmtime 6.0, 7.0, upcoming 8.0, and corresponding Cranelift
  versions) so I think this is probably OK. As an alternative if anyone
  feels strongly, we could leave the setting and make it a no-op.

* Update test outputs for remaining test differences.
This commit is contained in:
Chris Fallin
2023-04-06 11:11:03 -07:00
committed by GitHub
parent 465913eb2c
commit 230e2135d6
325 changed files with 3522 additions and 8783 deletions

View File

@@ -41,13 +41,10 @@ mod test_dce;
mod test_domtree;
mod test_interpret;
mod test_legalizer;
mod test_licm;
mod test_optimize;
mod test_print_cfg;
mod test_run;
mod test_safepoint;
mod test_simple_gvn;
mod test_simple_preopt;
mod test_unwind;
mod test_verifier;
mod test_wasm;
@@ -114,13 +111,10 @@ fn new_subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn subtest::SubTest>
"domtree" => test_domtree::subtest(parsed),
"interpret" => test_interpret::subtest(parsed),
"legalizer" => test_legalizer::subtest(parsed),
"licm" => test_licm::subtest(parsed),
"optimize" => test_optimize::subtest(parsed),
"print-cfg" => test_print_cfg::subtest(parsed),
"run" => test_run::subtest(parsed),
"safepoint" => test_safepoint::subtest(parsed),
"simple-gvn" => test_simple_gvn::subtest(parsed),
"simple_preopt" => test_simple_preopt::subtest(parsed),
"unwind" => test_unwind::subtest(parsed),
"verifier" => test_verifier::subtest(parsed),
_ => anyhow::bail!("unknown test command '{}'", parsed.command),

View File

@@ -35,9 +35,6 @@ impl SubTest for TestAliasAnalysis {
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
comp_ctx.flowgraph();
comp_ctx
.simple_gvn(context.flags_or_isa())
.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;
comp_ctx
.replace_redundant_loads()
.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;

View File

@@ -1,51 +0,0 @@
//! Test command for testing the LICM pass.
//!
//! The `licm` test command runs each function through the LICM pass after ensuring
//! that all instructions are legal for the target.
//!
//! The resulting function is sent to `filecheck`.
use crate::subtest::{run_filecheck, Context, SubTest};
use cranelift_codegen;
use cranelift_codegen::ir::Function;
use cranelift_reader::TestCommand;
use std::borrow::Cow;
struct TestLICM;
pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
assert_eq!(parsed.command, "licm");
if !parsed.options.is_empty() {
anyhow::bail!("No options allowed on {}", parsed);
}
Ok(Box::new(TestLICM))
}
impl SubTest for TestLICM {
fn name(&self) -> &'static str {
"licm"
}
fn needs_isa(&self) -> bool {
true
}
fn is_mutating(&self) -> bool {
true
}
fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {
let isa = context.isa.expect("LICM needs an ISA");
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
comp_ctx.flowgraph();
comp_ctx.compute_loop_analysis();
comp_ctx
.licm(isa)
.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;
let text = comp_ctx.func.display().to_string();
log::debug!("Post-LICM CLIF:\n{}", text);
run_filecheck(&text, context)
}
}

View File

@@ -1,44 +0,0 @@
//! Test command for testing the simple GVN pass.
//!
//! The `simple-gvn` test command runs each function through the simple GVN pass after ensuring
//! that all instructions are legal for the target.
//!
//! The resulting function is sent to `filecheck`.
use crate::subtest::{run_filecheck, Context, SubTest};
use cranelift_codegen;
use cranelift_codegen::ir::Function;
use cranelift_reader::TestCommand;
use std::borrow::Cow;
struct TestSimpleGVN;
pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
assert_eq!(parsed.command, "simple-gvn");
if !parsed.options.is_empty() {
anyhow::bail!("No options allowed on {}", parsed);
}
Ok(Box::new(TestSimpleGVN))
}
impl SubTest for TestSimpleGVN {
fn name(&self) -> &'static str {
"simple-gvn"
}
fn is_mutating(&self) -> bool {
true
}
fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
comp_ctx.flowgraph();
comp_ctx
.simple_gvn(context.flags_or_isa())
.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;
let text = comp_ctx.func.display().to_string();
run_filecheck(&text, context)
}
}

View File

@@ -1,46 +0,0 @@
//! Test command for testing the preopt pass.
//!
//! The resulting function is sent to `filecheck`.
use crate::subtest::{run_filecheck, Context, SubTest};
use cranelift_codegen;
use cranelift_codegen::ir::Function;
use cranelift_reader::TestCommand;
use std::borrow::Cow;
struct TestSimplePreopt;
pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
assert_eq!(parsed.command, "simple_preopt");
if !parsed.options.is_empty() {
anyhow::bail!("No options allowed on {}", parsed);
}
Ok(Box::new(TestSimplePreopt))
}
impl SubTest for TestSimplePreopt {
fn name(&self) -> &'static str {
"simple_preopt"
}
fn needs_isa(&self) -> bool {
true
}
fn is_mutating(&self) -> bool {
true
}
fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
let isa = context.isa.expect("preopt needs an ISA");
comp_ctx.compute_cfg();
comp_ctx
.preopt(isa)
.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, e))?;
let text = &comp_ctx.func.display().to_string();
log::debug!("After simple_preopt:\n{}", text);
run_filecheck(&text, context)
}
}