From 9b97ddf29a10ec9c73d5e2afe5013eaff9e4b5ba Mon Sep 17 00:00:00 2001 From: Sean Stangl Date: Thu, 18 Jul 2019 09:59:28 -0600 Subject: [PATCH] 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. --- cranelift/codegen/Cargo.toml | 3 +++ cranelift/codegen/src/verifier/mod.rs | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index aa579c4cde..a9834dac07 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -62,6 +62,9 @@ riscv = [] # For dependent crates that want to serialize some parts of cranelift enable-serde = ["serde"] +# Temporary feature that enforces basic block semantics. +basic-blocks = [] + [badges] maintenance = { status = "experimental" } travis-ci = { repository = "CraneStation/cranelift" } diff --git a/cranelift/codegen/src/verifier/mod.rs b/cranelift/codegen/src/verifier/mod.rs index 694e5e46de..276e43adf9 100644 --- a/cranelift/codegen/src/verifier/mod.rs +++ b/cranelift/codegen/src/verifier/mod.rs @@ -267,8 +267,6 @@ struct Verifier<'a> { expected_cfg: ControlFlowGraph, expected_domtree: DominatorTree, isa: Option<&'a dyn TargetIsa>, - // To be removed when #796 is completed. - verify_encodable_as_bb: bool, } impl<'a> Verifier<'a> { @@ -280,7 +278,6 @@ impl<'a> Verifier<'a> { expected_cfg, expected_domtree, 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 /// branching instructions are ending the EBB. + #[cfg(feature = "basic-blocks")] 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 inst_iter = self.func.layout.ebb_insts(ebb); // Skip non-branching instructions. @@ -1794,6 +1787,8 @@ impl<'a> Verifier<'a> { self.verify_encoding(inst, errors)?; self.immediate_constraints(inst, errors)?; } + + #[cfg(feature = "basic-blocks")] self.encodable_as_bb(ebb, errors)?; }