Skip to content

Commit

Permalink
Add CodeGen options to allow for specifying optimize for size and min…
Browse files Browse the repository at this point in the history
…imum size

options.
Closes #32296
  • Loading branch information
brandonedens committed Mar 22, 2016
1 parent 399b522 commit 16dcdc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
2 = full debug info with variable and type information"),
opt_level: Option<usize> = (None, parse_opt_uint,
"optimize with possible levels 0-3"),
opt_size: Option<usize> = (None, parse_opt_uint,
"optimize for size levels 0-2"),
debug_assertions: Option<bool> = (None, parse_opt_bool,
"explicitly enable the cfg(debug_assertions) directive"),
inline_threshold: Option<usize> = (None, parse_opt_uint,
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_trans/trans/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
llvm::SetFunctionAttribute(llfn, llvm::Attribute::NoRedZone)
}

let opt_size = ccx.tcx().sess.opts.cg.opt_size.unwrap_or(0);
if opt_size >= 1 {
llvm::SetFunctionAttribute(llfn, llvm::Attribute::OptimizeForSize);
}
if opt_size >= 2 {
llvm::SetFunctionAttribute(llfn, llvm::Attribute::MinSize);
}


llfn
}

Expand Down

0 comments on commit 16dcdc6

Please sign in to comment.