Skip to main content

cranelift_codegen/
lib.rs

1//! Cranelift code generation library.
2#![deny(missing_docs)]
3// Display feature requirements in the documentation when building on docs.rs
4#![cfg_attr(docsrs, feature(doc_cfg))]
5#![no_std]
6// Various bits and pieces of this crate might only be used for one platform or
7// another, but it's not really too useful to learn about that all the time. On
8// CI we build at least one version of this crate with `--features all-arch`
9// which means we'll always detect truly dead code, otherwise if this is only
10// built for one platform we don't have to worry too much about trimming
11// everything down.
12#![cfg_attr(
13    not(feature = "all-arch"),
14    allow(dead_code, reason = "see comment above")
15)]
16
17#[cfg_attr(not(feature = "std"), macro_use)]
18extern crate alloc;
19
20#[cfg(feature = "std")]
21#[macro_use]
22extern crate std;
23
24#[cfg(not(feature = "std"))]
25use hashbrown::{HashMap, HashSet, hash_map};
26#[cfg(feature = "std")]
27use std::collections::{HashMap, HashSet, hash_map};
28
29/// Type alias for a hash map that uses the Fx hashing algorithm.
30pub type FxHashMap<K, V> = HashMap<K, V, rustc_hash::FxBuildHasher>;
31/// Type alias for a hash set that uses the Fx hashing algorithm.
32pub type FxHashSet<V> = HashSet<V, rustc_hash::FxBuildHasher>;
33
34pub use crate::context::Context;
35pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange};
36pub use crate::verifier::verify_function;
37pub use crate::write::write_function;
38
39pub use cranelift_bforest as bforest;
40pub use cranelift_bitset as bitset;
41pub use cranelift_control as control;
42pub use cranelift_entity as entity;
43#[cfg(feature = "unwind")]
44pub use gimli;
45
46// Pull in generated the `isle_numerics_methods` macro.
47include!(concat!(env!("ISLE_DIR"), "/isle_numerics.rs"));
48
49#[macro_use]
50mod machinst;
51
52pub mod binemit;
53pub mod cfg_printer;
54pub mod cursor;
55pub mod data_value;
56pub mod dbg;
57pub mod dominator_tree;
58pub mod flowgraph;
59pub mod inline;
60pub mod ir;
61pub mod isa;
62pub mod loop_analysis;
63pub mod post_dominator_tree;
64pub mod print_errors;
65pub mod settings;
66pub mod timing;
67pub mod traversals;
68pub mod verifier;
69pub mod write;
70
71pub use crate::entity::packed_option;
72pub use crate::machinst::buffer::{
73    ExceptionContextLoc, FinalizedMachCallSite, FinalizedMachExceptionHandler, FinalizedMachReloc,
74    FinalizedRelocTarget, MachCallSite, MachSrcLoc, MachTextSectionBuilder, MachTrap,
75    OpenPatchRegion, PatchRegion,
76};
77pub use crate::machinst::{
78    CallInfo, CompiledCode, Final, FrameLayout, MachBuffer, MachBufferDebugTagList,
79    MachBufferFinalized, MachBufferFrameLayout, MachDebugTagPos, MachInst, MachInstEmit,
80    MachInstEmitState, MachLabel, RealReg, Reg, RegClass, RelocDistance, TextSectionBuilder,
81    VCodeConstant, VCodeConstantData, VCodeConstants, VCodeInst, Writable,
82};
83
84mod alias_analysis;
85mod branch_to_trap;
86mod constant_hash;
87mod context;
88mod ctxhash;
89mod egraph;
90mod inst_predicates;
91mod isle_prelude;
92mod nan_canonicalization;
93mod opts;
94mod ranges;
95mod remove_constant_phis;
96mod result;
97mod scoped_hash_map;
98mod take_and_replace;
99mod unreachable_code;
100mod value_label;
101
102#[cfg(feature = "souper-harvest")]
103mod souper_harvest;
104
105pub use crate::result::{CodegenError, CodegenResult, CompileError};
106pub use crate::take_and_replace::TakeAndReplace;
107
108#[cfg(feature = "incremental-cache")]
109pub mod incremental_cache;
110
111/// Even when trace logging is disabled, the trace macro has a significant performance cost so we
112/// disable it by default.
113#[macro_export]
114macro_rules! trace {
115    ($($tt:tt)*) => {
116        if cfg!(any(feature = "trace-log", debug_assertions)) {
117            ::log::trace!($($tt)*);
118        }
119    };
120}
121
122/// Dynamic check for whether trace logging is enabled.
123#[macro_export]
124macro_rules! trace_log_enabled {
125    () => {
126        cfg!(any(feature = "trace-log", debug_assertions))
127            && ::log::log_enabled!(::log::Level::Trace)
128    };
129}
130
131include!(concat!(env!("OUT_DIR"), "/version.rs"));