Skip to content

Commit 57dfb84

Browse files
committed
Combine -Zinstrument-function-*-opts into -Zinstrument-function
Try to reduce to number of command line options. Each framework has the option of parsing a string following a colon delimiter.
1 parent fed44db commit 57dfb84

18 files changed

Lines changed: 81 additions & 61 deletions

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,10 @@ fn instrument_function_attr<'ll>(
243243
));
244244
}
245245
}
246-
InstrumentFunction::XRay => {
246+
InstrumentFunction::XRay(options) => {
247247
// XRay instrumentation is similar to __cyg_profile_func_{enter,exit}.
248248
// Function prologue and epilogue are instrumented with NOP sleds,
249249
// a runtime library later replaces them with detours into tracing code.
250-
let options = &sess.opts.unstable_opts.instrument_xray_opts;
251250

252251
let mut never = options.never;
253252
let mut always = options.always;

compiler/rustc_session/src/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub enum InstrumentFunction {
160160
/// `-Z instrument-function=mcount`
161161
Mcount,
162162
/// `-Z instrument-function=xray`
163-
XRay,
163+
XRay(InstrumentXRayOpts),
164164
}
165165

166166
/// Individual flag values controlled by `-Zcoverage-options`.
@@ -261,19 +261,19 @@ pub enum AnnotateMoves {
261261

262262
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
263263
pub struct InstrumentXRayOpts {
264-
/// `-Z instrument-xray-opts=always`, force instrumentation
264+
/// `-Z instrument-function=xray:always`, force instrumentation
265265
pub always: bool,
266-
/// `-Z instrument-xray-opts=never`, disable instrumentation
266+
/// `-Z instrument-function=xray:never`, disable instrumentation
267267
pub never: bool,
268-
/// `-Z instrument-xray-opts=ignore-loops`, ignore presence of loops,
268+
/// `-Z instrument-function=xray:ignore-loops`, ignore presence of loops,
269269
/// instrument functions based only on instruction count
270270
pub ignore_loops: bool,
271-
/// `-Z instrument-xray-opts=instruction-threshold=N`, explicitly set instruction threshold
271+
/// `-Z instrument-function=xray:instruction-threshold=N`, explicitly set instruction threshold
272272
/// for instrumentation, or `None` to use compiler's default
273273
pub instruction_threshold: Option<usize>,
274-
/// `-Z instrument-xray-opts=skip-entry`, do not instrument function entry
274+
/// `-Z instrument-function=xray:skip-entry`, do not instrument function entry
275275
pub skip_entry: bool,
276-
/// `-Z instrument-xray-opts=skip-exit`, do not instrument function exit
276+
/// `-Z instrument-function=xray:skip-exit`, do not instrument function exit
277277
pub skip_exit: bool,
278278
}
279279

compiler/rustc_session/src/options.rs

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,7 @@ mod desc {
783783
pub(crate) const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
784784
pub(crate) const parse_instrument_coverage: &str = parse_bool;
785785
pub(crate) const parse_coverage_options: &str = "`block` | `branch` | `condition`";
786-
pub(crate) const parse_instrument_function: &str = "`fentry` | `mcount` | `xray`";
787-
pub(crate) const parse_instrument_xray_opts: &str = "a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
786+
pub(crate) const parse_instrument_function: &str = "`fentry` | `mcount` | `xray`, and an optional colon with a list of comma separated options.";
788787
pub(crate) const parse_unpretty: &str = "`string` or `string=string`";
789788
pub(crate) const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
790789
pub(crate) const parse_next_solver_config: &str =
@@ -1543,15 +1542,42 @@ pub mod parse {
15431542
slot: &mut InstrumentFunction,
15441543
v: Option<&str>,
15451544
) -> bool {
1545+
// Argument looks like the regex: type(:sub_opt(,sub_opt)*)?
15461546
let Some(v) = v else { return false };
1547-
match v {
1548-
"fentry" => *slot = InstrumentFunction::Fentry,
1549-
"mcount" => *slot = InstrumentFunction::Mcount,
1550-
"xray" => *slot = InstrumentFunction::XRay,
1551-
"none" => *slot = InstrumentFunction::No,
1552-
_ => return false,
1547+
let opts: Vec<_> = v.split(':').collect();
1548+
if opts.len() > 2 {
1549+
println!("too many opts");
1550+
return false;
15531551
}
1554-
true
1552+
let sub_opts = opts.get(1).copied();
1553+
let mut parsed = false;
1554+
1555+
match opts[0] {
1556+
"fentry" => {
1557+
parsed = sub_opts.is_none();
1558+
*slot = InstrumentFunction::Fentry;
1559+
}
1560+
"mcount" => {
1561+
parsed = sub_opts.is_none();
1562+
*slot = InstrumentFunction::Mcount;
1563+
}
1564+
"xray" => {
1565+
// Accept this option multiple times, this allows replacing or
1566+
// specifying additional options.
1567+
let mut xray_opts = match slot {
1568+
InstrumentFunction::XRay(opts) => opts,
1569+
_ => &mut InstrumentXRayOpts::default(),
1570+
};
1571+
parsed = parse_instrument_xray_opts(&mut xray_opts, sub_opts);
1572+
*slot = InstrumentFunction::XRay(*xray_opts);
1573+
}
1574+
"none" => {
1575+
parsed = sub_opts.is_none();
1576+
*slot = InstrumentFunction::No;
1577+
}
1578+
_ => {}
1579+
}
1580+
parsed
15551581
}
15561582

15571583
pub(crate) fn parse_instrument_xray_opts(
@@ -2400,17 +2426,12 @@ options! {
24002426
input_stats: bool = (false, parse_bool, [UNTRACKED],
24012427
"print some statistics about AST and HIR (default: no)"),
24022428
instrument_function: InstrumentFunction = (InstrumentFunction::No, parse_instrument_function, [TRACKED],
2403-
"insert function entry/exit instrument code. Options are none, xray, mcount, fentry. The default is none."),
2404-
instrument_xray_opts: InstrumentXRayOpts = (InstrumentXRayOpts::default(), parse_instrument_xray_opts, [TRACKED],
2405-
"configuration options for XRay-based tracing (default is ``).
2406-
Optional extra settings:
2407-
`=always`
2408-
`=never`
2409-
`=ignore-loops`
2410-
`=instruction-threshold=N`
2411-
`=skip-entry`
2412-
`=skip-exit`
2413-
Multiple options can be combined with commas."),
2429+
"insert function instrument code for tracing (default: none).
2430+
Instrumentation options are:
2431+
`xray`, `mcount`, or `fentry`
2432+
Additional configuration options can be set with a colon followed
2433+
by a comma separated list (e.g `xray:ignore-loops`).
2434+
`xray`: always,never,ignore-loops,instruction-threshold=N,skip-entry,skip-exit"),
24142435
large_data_threshold: Option<u64> = (None, parse_opt_number, [TRACKED],
24152436
"set the threshold for objects to be stored in a \"large data\" section \
24162437
(only effective with -Ccode-model=medium, default: 65536)"),

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13381338
.emit_err(errors::InstrumentationNotSupported { us: "fentry".to_string() });
13391339
}
13401340
}
1341-
InstrumentFunction::XRay => {
1341+
InstrumentFunction::XRay(_) => {
13421342
if !sess.target.options.supports_xray {
13431343
sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() });
13441344
}

src/doc/unstable-book/src/compiler-flags/instrument-function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ and/or the [XRay whitepaper](http://research.google.com/pubs/pub45287.html).
8181
Set the `-Z instrument-function=xray` compiler flag in order to enable XRay instrumentation.
8282

8383
- `-Z instrument-function=xray` – use the default settings
84-
- `-Z instrument-function=xray -Z instrument-xray-opts=skip-exit` – configure a custom setting
85-
- `-Z instrument-function=xray -Z instrument-xray-opts=ignore-loops,instruction-threshold=300`
84+
- `-Z instrument-function=xray:skip-exit` – configure a custom setting
85+
- `-Z instrument-function=xray:ignore-loops,instruction-threshold=300`
8686
multiple settings separated by commas
8787

8888
Supported options:

tests/assembly-llvm/aarch64-xray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ assembly-output: emit-asm
2-
//@ compile-flags: -Zinstrument-function=xray -Zinstrument-xray-opts=always
2+
//@ compile-flags: -Zinstrument-function=xray:always
33

44
//@ revisions: aarch64-linux
55
//@[aarch64-linux] compile-flags: --target=aarch64-unknown-linux-gnu

tests/assembly-llvm/x86_64-xray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ assembly-output: emit-asm
2-
//@ compile-flags: -Zinstrument-function=xray -Zinstrument-xray-opts=always -Cllvm-args=-x86-asm-syntax=intel
2+
//@ compile-flags: -Zinstrument-function=xray:always -Cllvm-args=-x86-asm-syntax=intel
33

44
//@ revisions: x86_64-linux
55
//@[x86_64-linux] compile-flags: --target=x86_64-unknown-linux-gnu

tests/codegen-llvm/instrument-xray/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Checks that `-Z instrument-function=xray -Z instrument-xray-opts`
1+
// Checks that `-Z instrument-function=xray:always`
22
// produces expected instrumentation.
33
//
44
//@ needs-xray
5-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=always -Copt-level=0
5+
//@ compile-flags: -Z instrument-function=xray:always -Copt-level=0
66

77
#![crate_type = "lib"]
88

tests/codegen-llvm/instrument-xray/options-combine.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Checks that `-Z instrument-xray-opts` options can be specified multiple times.
1+
// Checks that `-Z instrument-function=xray:<opt>` options can be specified multiple times.
22
//
33
//@ needs-xray
4-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=skip-exit -Copt-level=0
5-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=instruction-threshold=123 -Copt-level=0
6-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=instruction-threshold=456 -Copt-level=0
4+
//@ compile-flags: -Z instrument-function=xray:skip-exit -Copt-level=0
5+
//@ compile-flags: -Z instrument-function=xray:instruction-threshold=123 -Copt-level=0
6+
//@ compile-flags: -Z instrument-function=xray:instruction-threshold=456 -Copt-level=0
77

88
#![crate_type = "lib"]
99

tests/codegen-llvm/instrument-xray/options-override.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Checks that the last `-Z instrument-xray-opts` option wins.
1+
// Checks that the last `-Z instrument-function=xray:opt` option wins.
22
//
33
//@ needs-xray
4-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=always -Copt-level=0
5-
//@ compile-flags: -Z instrument-function=xray -Z instrument-xray-opts=never -Copt-level=0
4+
//@ compile-flags: -Z instrument-function=xray:always -Copt-level=0
5+
//@ compile-flags: -Z instrument-function=xray:never -Copt-level=0
66

77
#![crate_type = "lib"]
88

0 commit comments

Comments
 (0)