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_auto_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(not(feature = "all-arch"), allow(dead_code))]
13#![expect(clippy::allow_attributes_without_reason, reason = "crate not migrated")]
14
15#[allow(unused_imports)] // #[macro_use] is required for no_std
16#[macro_use]
17extern crate alloc;
18
19#[cfg(feature = "std")]
20#[macro_use]
21extern crate std;
22
23#[cfg(not(feature = "std"))]
24use hashbrown::{HashMap, hash_map};
25#[cfg(feature = "std")]
26use std::collections::{HashMap, hash_map};
27
28pub use crate::context::Context;
29pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange};
30pub use crate::verifier::verify_function;
31pub use crate::write::write_function;
32
33pub use cranelift_bforest as bforest;
34pub use cranelift_bitset as bitset;
35pub use cranelift_control as control;
36pub use cranelift_entity as entity;
37#[cfg(feature = "unwind")]
38pub use gimli;
39
40// Pull in generated the `isle_numerics_methods` macro.
41include!(concat!(env!("ISLE_DIR"), "/isle_numerics.rs"));
42
43#[macro_use]
44mod machinst;
45
46pub mod binemit;
47pub mod cfg_printer;
48pub mod cursor;
49pub mod data_value;
50pub mod dbg;
51pub mod dominator_tree;
52pub mod flowgraph;
53pub mod ir;
54pub mod isa;
55pub mod loop_analysis;
56pub mod print_errors;
57pub mod settings;
58pub mod timing;
59pub mod traversals;
60pub mod verifier;
61pub mod write;
62
63pub use crate::entity::packed_option;
64pub use crate::machinst::buffer::{
65    FinalizedMachCallSite, FinalizedMachReloc, FinalizedRelocTarget, MachCallSite, MachSrcLoc,
66    MachTextSectionBuilder, MachTrap, OpenPatchRegion, PatchRegion,
67};
68pub use crate::machinst::{
69    CallInfo, CompiledCode, Final, MachBuffer, MachBufferFinalized, MachInst, MachInstEmit,
70    MachInstEmitState, MachLabel, RealReg, Reg, RelocDistance, TextSectionBuilder, VCodeConstant,
71    VCodeConstantData, VCodeConstants, VCodeInst, Writable,
72};
73
74mod alias_analysis;
75mod constant_hash;
76mod context;
77mod ctxhash;
78mod egraph;
79mod inst_predicates;
80mod isle_prelude;
81mod legalizer;
82mod nan_canonicalization;
83mod opts;
84mod ranges;
85mod remove_constant_phis;
86mod result;
87mod scoped_hash_map;
88mod take_and_replace;
89mod unreachable_code;
90mod value_label;
91
92#[cfg(feature = "souper-harvest")]
93mod souper_harvest;
94
95pub use crate::result::{CodegenError, CodegenResult, CompileError};
96pub use crate::take_and_replace::TakeAndReplace;
97
98#[cfg(feature = "incremental-cache")]
99pub mod incremental_cache;
100
101/// Even when trace logging is disabled, the trace macro has a significant performance cost so we
102/// disable it by default.
103#[macro_export]
104macro_rules! trace {
105    ($($tt:tt)*) => {
106        if cfg!(any(feature = "trace-log", debug_assertions)) {
107            ::log::trace!($($tt)*);
108        }
109    };
110}
111
112/// Dynamic check for whether trace logging is enabled.
113#[macro_export]
114macro_rules! trace_log_enabled {
115    () => {
116        cfg!(any(feature = "trace-log", debug_assertions))
117            && ::log::log_enabled!(::log::Level::Trace)
118    };
119}
120
121include!(concat!(env!("OUT_DIR"), "/version.rs"));