Enable basic block checks through a feature. (#856)

This allows prefixing BB-specific code with "#[cfg(feature = "basic-blocks")]",
which avoids having to reference an environment variable across the codebase.

The easiest way to enable the feature locally is to add the arguments
'features = ["basic-blocks"]' to the workspace Cargo.toml, where it defines
the cranelift-codegen dependency.
This commit is contained in:
Sean Stangl
2019-07-18 09:59:28 -06:00
committed by GitHub
parent 084e279def
commit 9b97ddf29a
2 changed files with 6 additions and 8 deletions

View File

@@ -62,6 +62,9 @@ riscv = []
# For dependent crates that want to serialize some parts of cranelift # For dependent crates that want to serialize some parts of cranelift
enable-serde = ["serde"] enable-serde = ["serde"]
# Temporary feature that enforces basic block semantics.
basic-blocks = []
[badges] [badges]
maintenance = { status = "experimental" } maintenance = { status = "experimental" }
travis-ci = { repository = "CraneStation/cranelift" } travis-ci = { repository = "CraneStation/cranelift" }

View File

@@ -267,8 +267,6 @@ struct Verifier<'a> {
expected_cfg: ControlFlowGraph, expected_cfg: ControlFlowGraph,
expected_domtree: DominatorTree, expected_domtree: DominatorTree,
isa: Option<&'a dyn TargetIsa>, isa: Option<&'a dyn TargetIsa>,
// To be removed when #796 is completed.
verify_encodable_as_bb: bool,
} }
impl<'a> Verifier<'a> { impl<'a> Verifier<'a> {
@@ -280,7 +278,6 @@ impl<'a> Verifier<'a> {
expected_cfg, expected_cfg,
expected_domtree, expected_domtree,
isa: fisa.isa, isa: fisa.isa,
verify_encodable_as_bb: std::env::var("CRANELIFT_BB").is_ok(),
} }
} }
@@ -473,12 +470,8 @@ impl<'a> Verifier<'a> {
/// Check that the given EBB can be encoded as a BB, by checking that only /// Check that the given EBB can be encoded as a BB, by checking that only
/// branching instructions are ending the EBB. /// branching instructions are ending the EBB.
#[cfg(feature = "basic-blocks")]
fn encodable_as_bb(&self, ebb: Ebb, errors: &mut VerifierErrors) -> VerifierStepResult<()> { fn encodable_as_bb(&self, ebb: Ebb, errors: &mut VerifierErrors) -> VerifierStepResult<()> {
// Skip this verification if the environment variable is not set.
if !self.verify_encodable_as_bb {
return Ok(());
};
let dfg = &self.func.dfg; let dfg = &self.func.dfg;
let inst_iter = self.func.layout.ebb_insts(ebb); let inst_iter = self.func.layout.ebb_insts(ebb);
// Skip non-branching instructions. // Skip non-branching instructions.
@@ -1794,6 +1787,8 @@ impl<'a> Verifier<'a> {
self.verify_encoding(inst, errors)?; self.verify_encoding(inst, errors)?;
self.immediate_constraints(inst, errors)?; self.immediate_constraints(inst, errors)?;
} }
#[cfg(feature = "basic-blocks")]
self.encodable_as_bb(ebb, errors)?; self.encodable_as_bb(ebb, errors)?;
} }