Skip to content

Commit 16dcdc6

Browse files
committed
Add CodeGen options to allow for specifying optimize for size and minimum size
options. Closes #32296
1 parent 399b522 commit 16dcdc6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
564564
2 = full debug info with variable and type information"),
565565
opt_level: Option<usize> = (None, parse_opt_uint,
566566
"optimize with possible levels 0-3"),
567+
opt_size: Option<usize> = (None, parse_opt_uint,
568+
"optimize for size levels 0-2"),
567569
debug_assertions: Option<bool> = (None, parse_opt_bool,
568570
"explicitly enable the cfg(debug_assertions) directive"),
569571
inline_threshold: Option<usize> = (None, parse_opt_uint,

src/librustc_trans/trans/declare.rs

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
6969
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoRedZone)
7070
}
7171

72+
let opt_size = ccx.tcx().sess.opts.cg.opt_size.unwrap_or(0);
73+
if opt_size >= 1 {
74+
llvm::SetFunctionAttribute(llfn, llvm::Attribute::OptimizeForSize);
75+
}
76+
if opt_size >= 2 {
77+
llvm::SetFunctionAttribute(llfn, llvm::Attribute::MinSize);
78+
}
79+
80+
7281
llfn
7382
}
7483

0 commit comments

Comments
 (0)