|
1 | 1 | use crate::base;
|
2 | 2 | use crate::traits::*;
|
| 3 | +use rustc_index::bit_set::BitSet; |
| 4 | +use rustc_index::IndexVec; |
3 | 5 | use rustc_middle::mir;
|
4 | 6 | use rustc_middle::mir::interpret::ErrorHandled;
|
| 7 | +use rustc_middle::mir::traversal; |
5 | 8 | use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
|
6 | 9 | use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
|
7 | 10 | use rustc_target::abi::call::{FnAbi, PassMode};
|
8 | 11 |
|
9 | 12 | use std::iter;
|
10 | 13 |
|
11 |
| -use rustc_index::bit_set::BitSet; |
12 |
| -use rustc_index::IndexVec; |
| 14 | +mod analyze; |
| 15 | +mod block; |
| 16 | +pub mod constant; |
| 17 | +pub mod coverageinfo; |
| 18 | +pub mod debuginfo; |
| 19 | +mod intrinsic; |
| 20 | +mod locals; |
| 21 | +pub mod operand; |
| 22 | +pub mod place; |
| 23 | +mod rvalue; |
| 24 | +mod statement; |
13 | 25 |
|
14 | 26 | use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo};
|
15 |
| -use self::place::PlaceRef; |
16 |
| -use rustc_middle::mir::traversal; |
17 |
| - |
18 | 27 | use self::operand::{OperandRef, OperandValue};
|
| 28 | +use self::place::PlaceRef; |
19 | 29 |
|
20 | 30 | // Used for tracking the state of generated basic blocks.
|
21 | 31 | enum CachedLlbb<T> {
|
@@ -91,7 +101,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
91 | 101 | ///
|
92 | 102 | /// Avoiding allocs can also be important for certain intrinsics,
|
93 | 103 | /// notably `expect`.
|
94 |
| - locals: IndexVec<mir::Local, LocalRef<'tcx, Bx::Value>>, |
| 104 | + locals: locals::Locals<'tcx, Bx::Value>, |
95 | 105 |
|
96 | 106 | /// All `VarDebugInfo` from the MIR body, partitioned by `Local`.
|
97 | 107 | /// This is `None` if no var`#[non_exhaustive]`iable debuginfo/names are needed.
|
@@ -192,7 +202,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
192 | 202 | cleanup_kinds,
|
193 | 203 | landing_pads: IndexVec::from_elem(None, &mir.basic_blocks),
|
194 | 204 | funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks.len()),
|
195 |
| - locals: IndexVec::new(), |
| 205 | + locals: locals::Locals::empty(), |
196 | 206 | debug_context,
|
197 | 207 | per_local_var_debug_info: None,
|
198 | 208 | caller_location: None,
|
@@ -223,7 +233,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
223 | 233 | let memory_locals = analyze::non_ssa_locals(&fx);
|
224 | 234 |
|
225 | 235 | // Allocate variable and temp allocas
|
226 |
| - fx.locals = { |
| 236 | + let local_values = { |
227 | 237 | let args = arg_local_refs(&mut start_bx, &mut fx, &memory_locals);
|
228 | 238 |
|
229 | 239 | let mut allocate_local = |local| {
|
@@ -256,6 +266,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
256 | 266 | .chain(mir.vars_and_temps_iter().map(allocate_local))
|
257 | 267 | .collect()
|
258 | 268 | };
|
| 269 | + fx.initialize_locals(local_values); |
259 | 270 |
|
260 | 271 | // Apply debuginfo to the newly allocated locals.
|
261 | 272 | fx.debug_introduce_locals(&mut start_bx);
|
@@ -289,14 +300,13 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
289 | 300 | .enumerate()
|
290 | 301 | .map(|(arg_index, local)| {
|
291 | 302 | let arg_decl = &mir.local_decls[local];
|
| 303 | + let arg_ty = fx.monomorphize(arg_decl.ty); |
292 | 304 |
|
293 | 305 | if Some(local) == mir.spread_arg {
|
294 | 306 | // This argument (e.g., the last argument in the "rust-call" ABI)
|
295 | 307 | // is a tuple that was spread at the ABI level and now we have
|
296 | 308 | // to reconstruct it into a tuple local variable, from multiple
|
297 | 309 | // individual LLVM function arguments.
|
298 |
| - |
299 |
| - let arg_ty = fx.monomorphize(arg_decl.ty); |
300 | 310 | let ty::Tuple(tupled_arg_tys) = arg_ty.kind() else {
|
301 | 311 | bug!("spread argument isn't a tuple?!");
|
302 | 312 | };
|
@@ -331,8 +341,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
331 | 341 | }
|
332 | 342 |
|
333 | 343 | if fx.fn_abi.c_variadic && arg_index == fx.fn_abi.args.len() {
|
334 |
| - let arg_ty = fx.monomorphize(arg_decl.ty); |
335 |
| - |
336 | 344 | let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
|
337 | 345 | bx.va_start(va_list.llval);
|
338 | 346 |
|
@@ -429,14 +437,3 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
429 | 437 |
|
430 | 438 | args
|
431 | 439 | }
|
432 |
| - |
433 |
| -mod analyze; |
434 |
| -mod block; |
435 |
| -pub mod constant; |
436 |
| -pub mod coverageinfo; |
437 |
| -pub mod debuginfo; |
438 |
| -mod intrinsic; |
439 |
| -pub mod operand; |
440 |
| -pub mod place; |
441 |
| -mod rvalue; |
442 |
| -mod statement; |
0 commit comments