cranelift_codegen/
lib.rs

1//! Cranelift code generation library.
2#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
3#![warn(unused_import_braces)]
4#![cfg_attr(feature = "std", deny(unstable_features))]
5#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
6#![cfg_attr(feature="cargo-clippy", allow(
7// Produces only a false positive:
8                clippy::while_let_loop,
9// Produces many false positives, but did produce some valid lints, now fixed:
10                clippy::needless_lifetimes,
11// Generated code makes some style transgressions, but readability doesn't suffer much:
12                clippy::many_single_char_names,
13                clippy::identity_op,
14                clippy::needless_borrow,
15                clippy::cast_lossless,
16                clippy::unreadable_literal,
17                clippy::assign_op_pattern,
18                clippy::empty_line_after_outer_attr,
19// Hard to avoid in generated code:
20                clippy::cognitive_complexity,
21                clippy::too_many_arguments,
22// Code generator doesn't have a way to collapse identical arms:
23                clippy::match_same_arms,
24// These are relatively minor style issues, but would be easy to fix:
25                clippy::new_without_default,
26                clippy::should_implement_trait,
27                clippy::len_without_is_empty))]
28#![cfg_attr(
29    feature = "cargo-clippy",
30    warn(
31        clippy::float_arithmetic,
32        clippy::mut_mut,
33        clippy::nonminimal_bool,
34        clippy::map_unwrap_or,
35        clippy::unicode_not_nfc,
36        clippy::use_self
37    )
38)]
39#![no_std]
40// Various bits and pieces of this crate might only be used for one platform or
41// another, but it's not really too useful to learn about that all the time. On
42// CI we build at least one version of this crate with `--features all-arch`
43// which means we'll always detect truly dead code, otherwise if this is only
44// built for one platform we don't have to worry too much about trimming
45// everything down.
46#![cfg_attr(not(feature = "all-arch"), allow(dead_code))]
47
48#[allow(unused_imports)] // #[macro_use] is required for no_std
49#[macro_use]
50extern crate alloc;
51
52#[cfg(feature = "std")]
53#[macro_use]
54extern crate std;
55
56#[cfg(not(feature = "std"))]
57use hashbrown::{hash_map, HashMap, HashSet};
58#[cfg(feature = "std")]
59use std::collections::{hash_map, HashMap, HashSet};
60
61pub use crate::context::Context;
62pub use crate::value_label::{ValueLabelsRanges, ValueLocRange};
63pub use crate::verifier::verify_function;
64pub use crate::write::write_function;
65
66pub use cranelift_bforest as bforest;
67pub use cranelift_entity as entity;
68#[cfg(feature = "unwind")]
69pub use gimli;
70
71#[macro_use]
72mod machinst;
73
74pub mod binemit;
75pub mod cfg_printer;
76pub mod cursor;
77pub mod data_value;
78pub mod dbg;
79pub mod dominator_tree;
80pub mod flowgraph;
81pub mod ir;
82pub mod isa;
83pub mod loop_analysis;
84pub mod print_errors;
85pub mod settings;
86pub mod timing;
87pub mod verifier;
88pub mod write;
89
90pub use crate::entity::packed_option;
91pub use crate::machinst::buffer::{
92    MachCallSite, MachReloc, MachSrcLoc, MachStackMap, MachTextSectionBuilder, MachTrap,
93};
94pub use crate::machinst::{
95    CompiledCode, Final, MachBuffer, MachBufferFinalized, MachInst, MachInstEmit, Reg,
96    TextSectionBuilder, Writable,
97};
98
99mod alias_analysis;
100mod bitset;
101mod constant_hash;
102mod context;
103mod ctxhash;
104mod dce;
105mod divconst_magic_numbers;
106mod egraph;
107mod fx;
108mod inst_predicates;
109mod isle_prelude;
110mod iterators;
111mod legalizer;
112mod licm;
113mod nan_canonicalization;
114mod opts;
115mod remove_constant_phis;
116mod result;
117mod scoped_hash_map;
118mod simple_gvn;
119mod simple_preopt;
120mod unionfind;
121mod unreachable_code;
122mod value_label;
123
124#[cfg(feature = "souper-harvest")]
125mod souper_harvest;
126
127pub use crate::result::{CodegenError, CodegenResult, CompileError};
128
129#[cfg(feature = "incremental-cache")]
130pub mod incremental_cache;
131
132/// Even when trace logging is disabled, the trace macro has a significant performance cost so we
133/// disable it by default.
134#[macro_export]
135macro_rules! trace {
136    ($($tt:tt)*) => {
137        if cfg!(feature = "trace-log") {
138            ::log::trace!($($tt)*);
139        }
140    };
141}
142
143include!(concat!(env!("OUT_DIR"), "/version.rs"));