@@ -40,77 +40,159 @@ use tracing::{debug, trace};
4040#[ macro_use]
4141mod pass_manager;
4242
43+ use std:: sync:: LazyLock ;
44+
4345use pass_manager:: { self as pm, Lint , MirLint , MirPass , WithMinOptLevel } ;
4446
45- mod abort_unwinding_calls;
46- mod add_call_guards;
47- mod add_moves_for_packed_drops;
48- mod add_retag;
49- mod add_subtyping_projections;
50- mod check_alignment;
51- mod check_const_item_mutation;
52- mod check_packed_ref;
53- mod check_undefined_transmutes;
54- // This pass is public to allow external drivers to perform MIR cleanup
55- pub mod cleanup_post_borrowck;
56- mod copy_prop;
57- mod coroutine;
5847mod cost_checker;
59- mod coverage;
6048mod cross_crate_inline;
61- mod ctfe_limit;
62- mod dataflow_const_prop;
63- mod dead_store_elimination;
6449mod deduce_param_attrs;
65- mod deduplicate_blocks;
66- mod deref_separator;
67- mod dest_prop;
68- pub mod dump_mir;
69- mod early_otherwise_branch;
70- mod elaborate_box_derefs;
71- mod elaborate_drops;
7250mod errors;
7351mod ffi_unwind_calls;
74- mod function_item_references;
75- mod gvn;
76- // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
77- // by custom rustc drivers, running all the steps by themselves. See #114628.
78- pub mod inline;
79- mod instsimplify;
80- mod jump_threading;
81- mod known_panics_lint;
82- mod large_enums;
8352mod lint;
84- mod lower_intrinsics;
85- mod lower_slice_len;
86- mod match_branches;
87- mod mentioned_items;
88- mod multiple_return_terminators;
89- mod nrvo;
90- mod post_drop_elaboration;
91- mod prettify;
92- mod promote_consts;
93- mod ref_prop;
94- mod remove_noop_landing_pads;
95- mod remove_place_mention;
96- mod remove_storage_markers;
97- mod remove_uninit_drops;
98- mod remove_unneeded_drops;
99- mod remove_zsts;
100- mod required_consts;
101- mod reveal_all;
102- mod sanity_check;
10353mod shim;
10454mod ssa;
105- // This pass is public to allow external drivers to perform MIR cleanup
106- pub mod simplify;
107- mod simplify_branches;
108- mod simplify_comparison_integral;
109- mod single_use_consts;
110- mod sroa;
111- mod unreachable_enum_branching;
112- mod unreachable_prop;
113- mod validate;
55+
56+ /// We import passes via this macro so that we can have a static list of pass names
57+ /// (used to verify CLI arguments). It takes a list of modules, followed by the passes
58+ /// declared within them.
59+ /// ```ignore,macro-test
60+ /// declare_passes! {
61+ /// // Declare a single pass from the module `abort_unwinding_calls`
62+ /// mod abort_unwinding_calls : AbortUnwindingCalls;
63+ /// // When passes are grouped together as an enum, declare the two constituent passes
64+ /// mod add_call_guards : AddCallGuards {
65+ /// AllCallEdges,
66+ /// CriticalCallEdges
67+ /// };
68+ /// // Declares multiple pass groups, each containing their own constituent passes
69+ /// mod simplify : SimplifyCfg {
70+ /// Initial,
71+ /// /* omitted */
72+ /// }, SimplifyLocals {
73+ /// BeforeConstProp,
74+ /// /* omitted */
75+ /// };
76+ /// }
77+ /// ```
78+ macro_rules! declare_passes {
79+ (
80+ $(
81+ $vis: vis mod $mod_name: ident : $( $pass_name: ident $( { $( $ident: ident) ,* } ) ?) ,+ $( , ) ?;
82+ ) *
83+ ) => {
84+ $(
85+ $vis mod $mod_name;
86+ $(
87+ // Make sure the type name is correct
88+ #[ allow( unused_imports) ]
89+ use $mod_name:: $pass_name as _;
90+ ) +
91+ ) *
92+
93+ #[ cfg( debug_assertions) ]
94+ static PASS_NAMES : LazyLock <Vec <String >> = LazyLock :: new( || vec![
95+ // Fake marker pass
96+ "PreCodegen" . to_string( ) ,
97+ $(
98+ $(
99+ stringify!( $pass_name) . to_string( ) ,
100+ $(
101+ $(
102+ $mod_name:: $pass_name:: $ident. name( ) . to_string( ) ,
103+ ) *
104+ ) ?
105+ ) +
106+ ) *
107+ ] ) ;
108+ } ;
109+ }
110+
111+ declare_passes ! {
112+ mod abort_unwinding_calls : AbortUnwindingCalls ;
113+ mod add_call_guards : AddCallGuards { AllCallEdges , CriticalCallEdges } ;
114+ mod add_moves_for_packed_drops : AddMovesForPackedDrops ;
115+ mod add_retag : AddRetag ;
116+ mod add_subtyping_projections : Subtyper ;
117+ mod check_alignment : CheckAlignment ;
118+ mod check_const_item_mutation : CheckConstItemMutation ;
119+ mod check_packed_ref : CheckPackedRef ;
120+ mod check_undefined_transmutes : CheckUndefinedTransmutes ;
121+ // This pass is public to allow external drivers to perform MIR cleanup
122+ pub mod cleanup_post_borrowck : CleanupPostBorrowck ;
123+
124+ mod copy_prop : CopyProp ;
125+ mod coroutine : StateTransform ;
126+ mod coverage : InstrumentCoverage ;
127+ mod ctfe_limit : CtfeLimit ;
128+ mod dataflow_const_prop : DataflowConstProp ;
129+ mod dead_store_elimination : DeadStoreElimination {
130+ Initial ,
131+ Final
132+ } ;
133+ mod deduplicate_blocks : DeduplicateBlocks ;
134+ mod deref_separator : Derefer ;
135+ mod dest_prop : DestinationPropagation ;
136+ pub mod dump_mir : Marker ;
137+ mod early_otherwise_branch : EarlyOtherwiseBranch ;
138+ mod elaborate_box_derefs : ElaborateBoxDerefs ;
139+ mod elaborate_drops : ElaborateDrops ;
140+ mod function_item_references : FunctionItemReferences ;
141+ mod gvn : GVN ;
142+ // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden
143+ // by custom rustc drivers, running all the steps by themselves. See #114628.
144+ pub mod inline : Inline ;
145+ mod instsimplify : InstSimplify { BeforeInline , AfterSimplifyCfg } ;
146+ mod jump_threading : JumpThreading ;
147+ mod known_panics_lint : KnownPanicsLint ;
148+ mod large_enums : EnumSizeOpt ;
149+ mod lower_intrinsics : LowerIntrinsics ;
150+ mod lower_slice_len : LowerSliceLenCalls ;
151+ mod match_branches : MatchBranchSimplification ;
152+ mod mentioned_items : MentionedItems ;
153+ mod multiple_return_terminators : MultipleReturnTerminators ;
154+ mod nrvo : RenameReturnPlace ;
155+ mod post_drop_elaboration : CheckLiveDrops ;
156+ mod prettify : ReorderBasicBlocks , ReorderLocals ;
157+ mod promote_consts : PromoteTemps ;
158+ mod ref_prop : ReferencePropagation ;
159+ mod remove_noop_landing_pads : RemoveNoopLandingPads ;
160+ mod remove_place_mention : RemovePlaceMention ;
161+ mod remove_storage_markers : RemoveStorageMarkers ;
162+ mod remove_uninit_drops : RemoveUninitDrops ;
163+ mod remove_unneeded_drops : RemoveUnneededDrops ;
164+ mod remove_zsts : RemoveZsts ;
165+ mod required_consts : RequiredConstsVisitor ;
166+ mod reveal_all : RevealAll ;
167+ mod sanity_check : SanityCheck ;
168+ // This pass is public to allow external drivers to perform MIR cleanup
169+ pub mod simplify :
170+ SimplifyCfg {
171+ Initial ,
172+ PromoteConsts ,
173+ RemoveFalseEdges ,
174+ PostAnalysis ,
175+ PreOptimizations ,
176+ Final ,
177+ MakeShim ,
178+ AfterUnreachableEnumBranching
179+ } ,
180+ SimplifyLocals {
181+ BeforeConstProp ,
182+ AfterGVN ,
183+ Final
184+ } ;
185+ mod simplify_branches : SimplifyConstCondition {
186+ AfterConstProp ,
187+ Final
188+ } ;
189+ mod simplify_comparison_integral : SimplifyComparisonIntegral ;
190+ mod single_use_consts : SingleUseConsts ;
191+ mod sroa : ScalarReplacementOfAggregates ;
192+ mod unreachable_enum_branching : UnreachableEnumBranching ;
193+ mod unreachable_prop : UnreachablePropagation ;
194+ mod validate : Validator ;
195+ }
114196
115197rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
116198
0 commit comments