From 652e526bb631376ad0bef490e999be3747d15ce7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 5 Oct 2018 09:12:47 -0700 Subject: [PATCH] Put TargetIsa's emit_inst under a "testing_hooks" feature. (#531) * Put TargetIsa's emit_inst under a "testing_hooks" feature. In practice, TargetIsa's emit_inst pulls in its own instantiation of the target-specifi `emit_inst` functions, which can be quite large, and LTO doesn't eliminate them because they're held live by TargetIsa's vtable. Fortunately, this function is only used by tests, so we can put it behind a feature flag. Fixes #530. * Add comments for `emit_inst` to clarify its purpose. --- lib/codegen/Cargo.toml | 3 +++ lib/codegen/src/isa/arm32/mod.rs | 5 ++++- lib/codegen/src/isa/arm64/mod.rs | 5 ++++- lib/codegen/src/isa/mod.rs | 6 ++++-- lib/codegen/src/isa/riscv/mod.rs | 5 ++++- lib/codegen/src/isa/x86/mod.rs | 5 ++++- lib/filetests/Cargo.toml | 2 +- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/codegen/Cargo.toml b/lib/codegen/Cargo.toml index b1757f95b5..7c1d2d0e9a 100644 --- a/lib/codegen/Cargo.toml +++ b/lib/codegen/Cargo.toml @@ -34,6 +34,9 @@ cranelift-codegen-meta = { path = "meta", version = "0.22.0" } default = ["std"] std = ["cranelift-entity/std", "cranelift-bforest/std", "target-lexicon/std"] core = ["hashmap_core"] +# This enables some additional functions useful for writing tests, but which +# can significantly increase the size of the library. +testing_hooks = [] [badges] maintenance = { status = "experimental" } diff --git a/lib/codegen/src/isa/arm32/mod.rs b/lib/codegen/src/isa/arm32/mod.rs index 3606c18676..cee753a5f0 100644 --- a/lib/codegen/src/isa/arm32/mod.rs +++ b/lib/codegen/src/isa/arm32/mod.rs @@ -7,7 +7,9 @@ mod registers; pub mod settings; use super::super::settings as shared_settings; -use binemit::{emit_function, CodeSink, MemoryCodeSink}; +#[cfg(feature = "testing_hooks")] +use binemit::CodeSink; +use binemit::{emit_function, MemoryCodeSink}; use ir; use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; @@ -111,6 +113,7 @@ impl TargetIsa for Isa { abi::allocatable_registers(func) } + #[cfg(feature = "testing_hooks")] fn emit_inst( &self, func: &ir::Function, diff --git a/lib/codegen/src/isa/arm64/mod.rs b/lib/codegen/src/isa/arm64/mod.rs index 96e62a9e37..830a109b52 100644 --- a/lib/codegen/src/isa/arm64/mod.rs +++ b/lib/codegen/src/isa/arm64/mod.rs @@ -7,7 +7,9 @@ mod registers; pub mod settings; use super::super::settings as shared_settings; -use binemit::{emit_function, CodeSink, MemoryCodeSink}; +#[cfg(feature = "testing_hooks")] +use binemit::CodeSink; +use binemit::{emit_function, MemoryCodeSink}; use ir; use isa::enc_tables::{lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; @@ -98,6 +100,7 @@ impl TargetIsa for Isa { abi::allocatable_registers(func) } + #[cfg(feature = "testing_hooks")] fn emit_inst( &self, func: &ir::Function, diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index 33e78c96da..c3766346b7 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -307,6 +307,10 @@ pub trait TargetIsa: fmt::Display { /// /// Note that this will call `put*` methods on the `sink` trait object via its vtable which /// is not the fastest way of emitting code. + /// + /// This function is under the "testing_hooks" feature, and is only suitable for use by + /// test harnesses. It increases code size, and is inefficient. + #[cfg(feature = "testing_hooks")] fn emit_inst( &self, func: &ir::Function, @@ -316,7 +320,5 @@ pub trait TargetIsa: fmt::Display { ); /// Emit a whole function into memory. - /// - /// This is more performant than calling `emit_inst` for each instruction. fn emit_function_to_memory(&self, func: &ir::Function, sink: &mut binemit::MemoryCodeSink); } diff --git a/lib/codegen/src/isa/riscv/mod.rs b/lib/codegen/src/isa/riscv/mod.rs index 1a09f89bc1..393219571f 100644 --- a/lib/codegen/src/isa/riscv/mod.rs +++ b/lib/codegen/src/isa/riscv/mod.rs @@ -7,7 +7,9 @@ mod registers; pub mod settings; use super::super::settings as shared_settings; -use binemit::{emit_function, CodeSink, MemoryCodeSink}; +#[cfg(feature = "testing_hooks")] +use binemit::CodeSink; +use binemit::{emit_function, MemoryCodeSink}; use ir; use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; @@ -105,6 +107,7 @@ impl TargetIsa for Isa { abi::allocatable_registers(func, &self.isa_flags) } + #[cfg(feature = "testing_hooks")] fn emit_inst( &self, func: &ir::Function, diff --git a/lib/codegen/src/isa/x86/mod.rs b/lib/codegen/src/isa/x86/mod.rs index 0546c648cd..1dfa62bf61 100644 --- a/lib/codegen/src/isa/x86/mod.rs +++ b/lib/codegen/src/isa/x86/mod.rs @@ -7,7 +7,9 @@ mod registers; pub mod settings; use super::super::settings as shared_settings; -use binemit::{emit_function, CodeSink, MemoryCodeSink}; +#[cfg(feature = "testing_hooks")] +use binemit::CodeSink; +use binemit::{emit_function, MemoryCodeSink}; use ir; use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; @@ -115,6 +117,7 @@ impl TargetIsa for Isa { abi::allocatable_registers(func, &self.triple) } + #[cfg(feature = "testing_hooks")] fn emit_inst( &self, func: &ir::Function, diff --git a/lib/filetests/Cargo.toml b/lib/filetests/Cargo.toml index 59c4309563..1ed2daf9e0 100644 --- a/lib/filetests/Cargo.toml +++ b/lib/filetests/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/CraneStation/cranelift" publish = false [dependencies] -cranelift-codegen = { path = "../codegen", version = "0.22.0" } +cranelift-codegen = { path = "../codegen", version = "0.22.0", features = ["testing_hooks"] } cranelift-reader = { path = "../reader", version = "0.22.0" } file-per-thread-logger = "0.1.1" filecheck = "0.4.0"