switch to limiting the number of init/uninit chunks
This commit is contained in:
parent
b7e5597491
commit
d5769e9843
@ -37,7 +37,7 @@ fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>(
|
|||||||
alloc: &'a Allocation,
|
alloc: &'a Allocation,
|
||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
) {
|
) {
|
||||||
let mut chunks = alloc
|
let chunks = alloc
|
||||||
.init_mask()
|
.init_mask()
|
||||||
.range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end));
|
.range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end));
|
||||||
|
|
||||||
@ -53,32 +53,20 @@ fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generating partially-uninit consts is limited to small allocations,
|
// Generating partially-uninit consts is limited to small numbers of chunks,
|
||||||
// to avoid the cost of generating large complex const expressions.
|
// to avoid the cost of generating large complex const expressions.
|
||||||
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
|
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
|
||||||
// and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
|
// and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
|
||||||
let allow_partially_uninit =
|
let max = cx.sess().opts.debugging_opts.uninit_const_chunk_threshold;
|
||||||
match cx.sess().opts.debugging_opts.partially_uninit_const_threshold {
|
let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;
|
||||||
Some(max) => range.len() <= max,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if allow_partially_uninit {
|
if allow_uninit_chunks {
|
||||||
llvals.extend(chunks.map(chunk_to_llval));
|
llvals.extend(chunks.map(chunk_to_llval));
|
||||||
} else {
|
} else {
|
||||||
let llval = match (chunks.next(), chunks.next()) {
|
// If this allocation contains any uninit bytes, codegen as if it was initialized
|
||||||
(Some(chunk), None) => {
|
// (using some arbitrary value for uninit bytes).
|
||||||
// exactly one chunk, either fully init or fully uninit
|
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
|
||||||
chunk_to_llval(chunk)
|
llvals.push(cx.const_bytes(bytes));
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// partially uninit, codegen as if it was initialized
|
|
||||||
// (using some arbitrary value for uninit bytes)
|
|
||||||
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
|
|
||||||
cx.const_bytes(bytes)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
llvals.push(llval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,7 +758,6 @@ macro_rules! tracked {
|
|||||||
tracked!(osx_rpath_install_name, true);
|
tracked!(osx_rpath_install_name, true);
|
||||||
tracked!(panic_abort_tests, true);
|
tracked!(panic_abort_tests, true);
|
||||||
tracked!(panic_in_drop, PanicStrategy::Abort);
|
tracked!(panic_in_drop, PanicStrategy::Abort);
|
||||||
tracked!(partially_uninit_const_threshold, Some(123));
|
|
||||||
tracked!(pick_stable_methods_before_any_unstable, false);
|
tracked!(pick_stable_methods_before_any_unstable, false);
|
||||||
tracked!(plt, Some(true));
|
tracked!(plt, Some(true));
|
||||||
tracked!(polonius, true);
|
tracked!(polonius, true);
|
||||||
@ -789,6 +788,7 @@ macro_rules! tracked {
|
|||||||
tracked!(trap_unreachable, Some(false));
|
tracked!(trap_unreachable, Some(false));
|
||||||
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
|
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
|
||||||
tracked!(tune_cpu, Some(String::from("abc")));
|
tracked!(tune_cpu, Some(String::from("abc")));
|
||||||
|
tracked!(uninit_const_chunk_threshold, 123);
|
||||||
tracked!(unleash_the_miri_inside_of_you, true);
|
tracked!(unleash_the_miri_inside_of_you, true);
|
||||||
tracked!(use_ctors_section, Some(true));
|
tracked!(use_ctors_section, Some(true));
|
||||||
tracked!(verify_llvm_ir, true);
|
tracked!(verify_llvm_ir, true);
|
||||||
|
@ -957,6 +957,7 @@ pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`].
|
/// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`].
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct InitChunkIter<'a> {
|
pub struct InitChunkIter<'a> {
|
||||||
init_mask: &'a InitMask,
|
init_mask: &'a InitMask,
|
||||||
/// Whether the next chunk we will return is initialized.
|
/// Whether the next chunk we will return is initialized.
|
||||||
|
@ -1341,9 +1341,6 @@ mod parse {
|
|||||||
"panic strategy for panics in drops"),
|
"panic strategy for panics in drops"),
|
||||||
parse_only: bool = (false, parse_bool, [UNTRACKED],
|
parse_only: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"parse only; do not compile, assemble, or link (default: no)"),
|
"parse only; do not compile, assemble, or link (default: no)"),
|
||||||
partially_uninit_const_threshold: Option<usize> = (Some(1024), parse_opt_number, [TRACKED],
|
|
||||||
"allow generating const initializers with mixed init/uninit bytes, \
|
|
||||||
and set the maximum total size of a const allocation for which this is allowed (default: 1024 bytes)"),
|
|
||||||
perf_stats: bool = (false, parse_bool, [UNTRACKED],
|
perf_stats: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"print some performance-related statistics (default: no)"),
|
"print some performance-related statistics (default: no)"),
|
||||||
pick_stable_methods_before_any_unstable: bool = (true, parse_bool, [TRACKED],
|
pick_stable_methods_before_any_unstable: bool = (true, parse_bool, [TRACKED],
|
||||||
@ -1488,6 +1485,9 @@ mod parse {
|
|||||||
"in diagnostics, use heuristics to shorten paths referring to items"),
|
"in diagnostics, use heuristics to shorten paths referring to items"),
|
||||||
ui_testing: bool = (false, parse_bool, [UNTRACKED],
|
ui_testing: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"emit compiler diagnostics in a form suitable for UI testing (default: no)"),
|
"emit compiler diagnostics in a form suitable for UI testing (default: no)"),
|
||||||
|
uninit_const_chunk_threshold: usize = (256, parse_number, [TRACKED],
|
||||||
|
"allow generating const initializers with mixed init/uninit chunks, \
|
||||||
|
and set the maximum number of chunks for which this is allowed (default: 256)"),
|
||||||
unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
|
unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
|
||||||
"take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
|
"take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
|
||||||
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
|
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
|
||||||
|
@ -15,7 +15,8 @@ pub struct PartiallyUninit {
|
|||||||
|
|
||||||
// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4
|
// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4
|
||||||
|
|
||||||
// This shouldn't contain undef, since it's larger than the 1024 byte limit.
|
// This shouldn't contain undef, since it contains more than 256 chunks
|
||||||
|
// (the default value of uninit_const_chunk_threshold).
|
||||||
// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4
|
// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4
|
||||||
|
|
||||||
// CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef
|
// CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef
|
||||||
|
Loading…
Reference in New Issue
Block a user