Always require a Flags reference for verifying functions.
Add a settings::FlagsOrIsa struct which represents a flags reference and optionally the ISA it belongs to. Use this for passing flags/isa information to the verifier. The verify_function() and verify_context() functions are now generic so they accept either a &Flags or a &TargetISa argument. Fix the return_at_end verifier tests which no longer require an ISA specified. The signle "set return_at_end" flag setting now makes it to the verifier even when no ISA is present to carry it.
This commit is contained in:
@@ -18,6 +18,7 @@ use isa::TargetIsa;
|
||||
use legalize_function;
|
||||
use regalloc;
|
||||
use result::{CtonError, CtonResult};
|
||||
use settings::FlagsOrIsa;
|
||||
use verifier;
|
||||
use simple_gvn::do_simple_gvn;
|
||||
use licm::do_licm;
|
||||
@@ -86,17 +87,14 @@ impl Context {
|
||||
/// Run the verifier on the function.
|
||||
///
|
||||
/// Also check that the dominator tree and control flow graph are consistent with the function.
|
||||
///
|
||||
/// The `isa` argument is currently unused, but the verifier will soon be able to also
|
||||
/// check ISA-dependent constraints.
|
||||
pub fn verify(&self, isa: Option<&TargetIsa>) -> verifier::Result {
|
||||
verifier::verify_context(&self.func, &self.cfg, &self.domtree, isa)
|
||||
pub fn verify<'a, FOI: Into<FlagsOrIsa<'a>>>(&self, fisa: FOI) -> verifier::Result {
|
||||
verifier::verify_context(&self.func, &self.cfg, &self.domtree, fisa)
|
||||
}
|
||||
|
||||
/// Run the verifier only if the `enable_verifier` setting is true.
|
||||
pub fn verify_if(&self, isa: &TargetIsa) -> CtonResult {
|
||||
if isa.flags().enable_verifier() {
|
||||
self.verify(Some(isa)).map_err(Into::into)
|
||||
self.verify(isa).map_err(Into::into)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -427,9 +427,10 @@ impl DominatorTree {
|
||||
mod test {
|
||||
use cursor::{Cursor, FuncCursor};
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use ir::{Function, InstBuilder, types};
|
||||
use super::*;
|
||||
use ir::types::*;
|
||||
use ir::{Function, InstBuilder, types};
|
||||
use settings;
|
||||
use super::*;
|
||||
use verifier::verify_context;
|
||||
|
||||
#[test]
|
||||
@@ -608,6 +609,8 @@ mod test {
|
||||
dt.recompute_split_ebb(ebb3, ebb4, middle_jump_inst);
|
||||
|
||||
cfg.compute(cur.func);
|
||||
verify_context(cur.func, &cfg, &dt, None).unwrap();
|
||||
|
||||
let flags = settings::Flags::new(&settings::builder());
|
||||
verify_context(cur.func, &cfg, &dt, &flags).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Context {
|
||||
);
|
||||
|
||||
if isa.flags().enable_verifier() {
|
||||
verify_context(func, cfg, domtree, Some(isa))?;
|
||||
verify_context(func, cfg, domtree, isa)?;
|
||||
verify_liveness(isa, func, cfg, &self.liveness)?;
|
||||
verify_cssa(func, cfg, domtree, &self.liveness, &self.virtregs)?;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ impl Context {
|
||||
);
|
||||
|
||||
if isa.flags().enable_verifier() {
|
||||
verify_context(func, cfg, domtree, Some(isa))?;
|
||||
verify_context(func, cfg, domtree, isa)?;
|
||||
verify_liveness(isa, func, cfg, &self.liveness)?;
|
||||
verify_cssa(func, cfg, domtree, &self.liveness, &self.virtregs)?;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ impl Context {
|
||||
);
|
||||
|
||||
if isa.flags().enable_verifier() {
|
||||
verify_context(func, cfg, domtree, Some(isa))?;
|
||||
verify_context(func, cfg, domtree, isa)?;
|
||||
verify_liveness(isa, func, cfg, &self.liveness)?;
|
||||
verify_cssa(func, cfg, domtree, &self.liveness, &self.virtregs)?;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ impl Context {
|
||||
);
|
||||
|
||||
if isa.flags().enable_verifier() {
|
||||
verify_context(func, cfg, domtree, Some(isa))?;
|
||||
verify_context(func, cfg, domtree, isa)?;
|
||||
verify_liveness(isa, func, cfg, &self.liveness)?;
|
||||
verify_cssa(func, cfg, domtree, &self.liveness, &self.virtregs)?;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
//! assert_eq!(f.opt_level(), settings::OptLevel::Fastest);
|
||||
//! ```
|
||||
|
||||
use constant_hash::{probe, simple_hash};
|
||||
use isa::TargetIsa;
|
||||
use std::fmt;
|
||||
use std::result;
|
||||
|
||||
use constant_hash::{probe, simple_hash};
|
||||
|
||||
/// A string-based configurator for settings groups.
|
||||
///
|
||||
/// The `Configurable` protocol allows settings to be modified by name before a finished `Flags`
|
||||
@@ -303,6 +303,34 @@ pub mod detail {
|
||||
// with an impl for all of the settings defined in `meta/cretonne/settings.py`.
|
||||
include!(concat!(env!("OUT_DIR"), "/settings.rs"));
|
||||
|
||||
/// Wrapper containing flags and optionally a `TargetIsa` trait object.
|
||||
///
|
||||
/// A few passes need to access the flags but only optionally a target ISA. The `FlagsOrIsa`
|
||||
/// wrapper can be used to pass either, and extract the flags so they are always accessible.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct FlagsOrIsa<'a> {
|
||||
/// Flags are always present.
|
||||
pub flags: &'a Flags,
|
||||
|
||||
/// The ISA may not be present.
|
||||
pub isa: Option<&'a TargetIsa>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Flags> for FlagsOrIsa<'a> {
|
||||
fn from(flags: &'a Flags) -> FlagsOrIsa {
|
||||
FlagsOrIsa { flags, isa: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a TargetIsa> for FlagsOrIsa<'a> {
|
||||
fn from(isa: &'a TargetIsa) -> FlagsOrIsa {
|
||||
FlagsOrIsa {
|
||||
flags: isa.flags(),
|
||||
isa: Some(isa),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{builder, Flags};
|
||||
|
||||
@@ -66,6 +66,7 @@ use ir::instructions::{InstructionFormat, BranchInfo, ResolvedConstraint, CallIn
|
||||
use ir::{types, Function, ValueDef, Ebb, Inst, SigRef, FuncRef, ValueList, JumpTable, StackSlot,
|
||||
StackSlotKind, GlobalVar, Value, Type, Opcode, ValueLoc, ArgumentLoc};
|
||||
use isa::TargetIsa;
|
||||
use settings::{Flags, FlagsOrIsa};
|
||||
use std::error as std_error;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::result;
|
||||
@@ -121,19 +122,19 @@ impl std_error::Error for Error {
|
||||
pub type Result = result::Result<(), Error>;
|
||||
|
||||
/// Verify `func`.
|
||||
pub fn verify_function(func: &Function, isa: Option<&TargetIsa>) -> Result {
|
||||
Verifier::new(func, isa).run()
|
||||
pub fn verify_function<'a, FOI: Into<FlagsOrIsa<'a>>>(func: &Function, fisa: FOI) -> Result {
|
||||
Verifier::new(func, fisa.into()).run()
|
||||
}
|
||||
|
||||
/// Verify `func` after checking the integrity of associated context data structures `cfg` and
|
||||
/// `domtree`.
|
||||
pub fn verify_context(
|
||||
pub fn verify_context<'a, FOI: Into<FlagsOrIsa<'a>>>(
|
||||
func: &Function,
|
||||
cfg: &ControlFlowGraph,
|
||||
domtree: &DominatorTree,
|
||||
isa: Option<&TargetIsa>,
|
||||
fisa: FOI,
|
||||
) -> Result {
|
||||
let verifier = Verifier::new(func, isa);
|
||||
let verifier = Verifier::new(func, fisa.into());
|
||||
if cfg.is_valid() {
|
||||
verifier.cfg_integrity(cfg)?;
|
||||
}
|
||||
@@ -147,18 +148,20 @@ struct Verifier<'a> {
|
||||
func: &'a Function,
|
||||
cfg: ControlFlowGraph,
|
||||
domtree: DominatorTree,
|
||||
flags: &'a Flags,
|
||||
isa: Option<&'a TargetIsa>,
|
||||
}
|
||||
|
||||
impl<'a> Verifier<'a> {
|
||||
pub fn new(func: &'a Function, isa: Option<&'a TargetIsa>) -> Verifier<'a> {
|
||||
pub fn new(func: &'a Function, fisa: FlagsOrIsa<'a>) -> Verifier<'a> {
|
||||
let cfg = ControlFlowGraph::with_function(func);
|
||||
let domtree = DominatorTree::with_function(func, &cfg);
|
||||
Verifier {
|
||||
func,
|
||||
cfg,
|
||||
domtree,
|
||||
isa,
|
||||
flags: fisa.flags,
|
||||
isa: fisa.isa,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,7 +974,7 @@ impl<'a> Verifier<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if self.isa.map(|isa| isa.flags().return_at_end()) == Some(true) {
|
||||
if self.flags.return_at_end() {
|
||||
self.verify_return_at_end()?;
|
||||
}
|
||||
|
||||
@@ -984,6 +987,7 @@ mod tests {
|
||||
use super::{Verifier, Error};
|
||||
use ir::Function;
|
||||
use ir::instructions::{InstructionData, Opcode};
|
||||
use settings;
|
||||
|
||||
macro_rules! assert_err_with_msg {
|
||||
($e:expr, $msg:expr) => (
|
||||
@@ -1001,7 +1005,8 @@ mod tests {
|
||||
#[test]
|
||||
fn empty() {
|
||||
let func = Function::new();
|
||||
let verifier = Verifier::new(&func, None);
|
||||
let flags = &settings::Flags::new(&settings::builder());
|
||||
let verifier = Verifier::new(&func, flags.into());
|
||||
assert_eq!(verifier.run(), Ok(()));
|
||||
}
|
||||
|
||||
@@ -1014,7 +1019,8 @@ mod tests {
|
||||
InstructionData::Nullary { opcode: Opcode::Jump },
|
||||
);
|
||||
func.layout.append_inst(nullary_with_bad_opcode, ebb0);
|
||||
let verifier = Verifier::new(&func, None);
|
||||
let flags = &settings::Flags::new(&settings::builder());
|
||||
let verifier = Verifier::new(&func, flags.into());
|
||||
assert_err_with_msg!(verifier.run(), "instruction format");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user