Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #69105

Merged
merged 41 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
97d47a5
Account for type params on method without parens
estebank Feb 9, 2020
202d401
miri: simplify singed operator overflow detection
RalfJung Feb 9, 2020
28f85c6
bring back extra check for int_min%-1
RalfJung Feb 9, 2020
7d2f6ae
miri: equip unary_op with overflow detection
RalfJung Feb 8, 2020
ae23f70
const-prop: use overflowing_unary_op for overflowing checking of unar…
RalfJung Feb 9, 2020
b434d7e
add test that checks overflows on arithmetic operators
RalfJung Feb 10, 2020
1ddb050
div/rem overflow tests: also test i128
RalfJung Feb 10, 2020
d6c5a04
some more tests for i128 oveflow behavior
RalfJung Feb 10, 2020
aeedc9d
Corrected ac_mitigation patch. That patch used the untrusted stack to…
raoulstrackx Feb 7, 2020
236ab6e
sanitize MXCSR/FPU control registers
raoulstrackx Feb 7, 2020
71b9ed4
Avoid jumping to Rust code with user %rsp (reentry_panic)
Feb 10, 2020
c561d23
remove outdated comment
RalfJung Feb 10, 2020
9d91489
review comment: wording
estebank Feb 10, 2020
b637c0e
Add initial debug fmt for Backtrace
yaahc Feb 10, 2020
4920456
Get vaguely working with a test for checking output
yaahc Feb 10, 2020
c0ba79e
less noisy format
yaahc Feb 10, 2020
0d5444f
remove unnecessary derives
yaahc Feb 10, 2020
76e6d6f
remove unnecessary Debug impl for BacktraceFrame
yaahc Feb 10, 2020
583dd2c
make it compile
yaahc Feb 10, 2020
8711778
final format cleanups
yaahc Feb 10, 2020
70c9133
remove Some from fn name
yaahc Feb 10, 2020
230ed3e
use debug_map and skip empty frames
yaahc Feb 11, 2020
de25048
add nice alt fmt for debug
yaahc Feb 11, 2020
192b103
make symbol printing consistent with backtrace_rs
yaahc Feb 11, 2020
7064a0e
maximum alternative consistency!
yaahc Feb 11, 2020
6797bfd
rule over the code in libstd with an iron fist
yaahc Feb 11, 2020
c8817aa
backwards again, god damnit
yaahc Feb 11, 2020
ec8ee7f
remove intentionally failing test
yaahc Feb 11, 2020
ee85e91
Update compiler-builtins to 0.1.25
tmandry Feb 12, 2020
03a73fa
Use IRBuilder to create memset
nikic Jan 5, 2020
737f08b
Fix mangled names of lifetime intrinsics
nikic Jan 5, 2020
c6b0803
Add support for new pass manager
nikic Jan 5, 2020
c8e567d
Minify CSS rules to be able to handle minified theme files as well
GuillaumeGomez Feb 12, 2020
109260f
Add test to check if minified theme are handled correctly
GuillaumeGomez Feb 12, 2020
f127aba
Rollup merge of #67954 - nikic:new-pm, r=nagisa
Dylan-DPC Feb 12, 2020
2a3c1a3
Rollup merge of #68981 - estebank:silence, r=davidtwco
Dylan-DPC Feb 12, 2020
29dd5df
Rollup merge of #69002 - RalfJung:miri-op-overflow, r=oli-obk,wesleyw…
Dylan-DPC Feb 12, 2020
5a800d7
Rollup merge of #69038 - yaahc:backtrace-debug, r=dtolnay
Dylan-DPC Feb 12, 2020
a908716
Rollup merge of #69040 - jethrogb:jb/cleanup-sgx-entry, r=nagisa
Dylan-DPC Feb 12, 2020
e86019c
Rollup merge of #69086 - tmandry:probestack-hidden-2, r=Dylan-DPC
Dylan-DPC Feb 12, 2020
839adda
Rollup merge of #69095 - GuillaumeGomez:minified-theme-check, r=Dylan…
Dylan-DPC Feb 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.24"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9975aefa63997ef75ca9cf013ff1bb81487aaa0b622c21053afd3b92979a7af"
checksum = "438ac08ddc5efe81452f984a9e33ba425b00b31d1f48e6acd9e2210aa28cc52e"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
14 changes: 14 additions & 0 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,20 @@ pub(crate) fn run_pass_manager(
// tools/lto/LTOCodeGenerator.cpp
debug!("running the pass manager");
unsafe {
if write::should_use_new_llvm_pass_manager(config) {
let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO };
let opt_level = config.opt_level.unwrap_or(config::OptLevel::No);
// See comment below for why this is necessary.
let opt_level = if let config::OptLevel::No = opt_level {
config::OptLevel::Less
} else {
opt_level
};
write::optimize_with_new_llvm_pass_manager(module, config, opt_level, opt_stage);
debug!("lto done");
return;
}

let pm = llvm::LLVMCreatePassManager();
llvm::LLVMAddAnalysisPasses(module.module_llvm.tm, pm);

Expand Down
125 changes: 107 additions & 18 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ pub fn to_llvm_opt_settings(
}
}

fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel {
use config::OptLevel::*;
match cfg {
No => llvm::PassBuilderOptLevel::O0,
Less => llvm::PassBuilderOptLevel::O1,
Default => llvm::PassBuilderOptLevel::O2,
Aggressive => llvm::PassBuilderOptLevel::O3,
Size => llvm::PassBuilderOptLevel::Os,
SizeMin => llvm::PassBuilderOptLevel::Oz,
}
}

// If find_features is true this won't access `sess.crate_types` by assuming
// that `is_pie_binary` is false. When we discover LLVM target features
// `sess.crate_types` is uninitialized so we cannot access it.
Expand Down Expand Up @@ -303,6 +315,88 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
}
}

fn get_pgo_gen_path(config: &ModuleConfig) -> Option<CString> {
match config.pgo_gen {
SwitchWithOptPath::Enabled(ref opt_dir_path) => {
let path = if let Some(dir_path) = opt_dir_path {
dir_path.join("default_%m.profraw")
} else {
PathBuf::from("default_%m.profraw")
};

Some(CString::new(format!("{}", path.display())).unwrap())
}
SwitchWithOptPath::Disabled => None,
}
}

fn get_pgo_use_path(config: &ModuleConfig) -> Option<CString> {
config
.pgo_use
.as_ref()
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
}

pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
// We only support the new pass manager starting with LLVM 9.
if llvm_util::get_major_version() < 9 {
return false;
}

// The new pass manager is disabled by default.
config.new_llvm_pass_manager.unwrap_or(false)
}

pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
module: &ModuleCodegen<ModuleLlvm>,
config: &ModuleConfig,
opt_level: config::OptLevel,
opt_stage: llvm::OptStage,
) {
let unroll_loops =
opt_level != config::OptLevel::Size && opt_level != config::OptLevel::SizeMin;
let using_thin_buffers = opt_stage == llvm::OptStage::PreLinkThinLTO || config.bitcode_needed();
let pgo_gen_path = get_pgo_gen_path(config);
let pgo_use_path = get_pgo_use_path(config);
let is_lto = opt_stage == llvm::OptStage::ThinLTO || opt_stage == llvm::OptStage::FatLTO;
// Sanitizer instrumentation is only inserted during the pre-link optimization stage.
let sanitizer_options = if !is_lto {
config.sanitizer.as_ref().map(|s| llvm::SanitizerOptions {
sanitize_memory: *s == Sanitizer::Memory,
sanitize_thread: *s == Sanitizer::Thread,
sanitize_address: *s == Sanitizer::Address,
sanitize_recover: config.sanitizer_recover.contains(s),
sanitize_memory_track_origins: config.sanitizer_memory_track_origins as c_int,
})
} else {
None
};

// FIXME: NewPM doesn't provide a facility to pass custom InlineParams.
// We would have to add upstream support for this first, before we can support
// config.inline_threshold and our more aggressive default thresholds.
// FIXME: NewPM uses an different and more explicit way to textually represent
// pass pipelines. It would probably make sense to expose this, but it would
// require a different format than the current -C passes.
llvm::LLVMRustOptimizeWithNewPassManager(
module.module_llvm.llmod(),
&*module.module_llvm.tm,
to_pass_builder_opt_level(opt_level),
opt_stage,
config.no_prepopulate_passes,
config.verify_llvm_ir,
using_thin_buffers,
config.merge_functions,
unroll_loops,
config.vectorize_slp,
config.vectorize_loop,
config.no_builtins,
sanitizer_options.as_ref(),
pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
);
}

// Unsafe due to LLVM calls.
pub(crate) unsafe fn optimize(
cgcx: &CodegenContext<LlvmCodegenBackend>,
Expand All @@ -327,6 +421,17 @@ pub(crate) unsafe fn optimize(
}

if let Some(opt_level) = config.opt_level {
if should_use_new_llvm_pass_manager(config) {
let opt_stage = match cgcx.lto {
Lto::Fat => llvm::OptStage::PreLinkFatLTO,
Lto::Thin | Lto::ThinLocal => llvm::OptStage::PreLinkThinLTO,
_ if cgcx.opts.cg.linker_plugin_lto.enabled() => llvm::OptStage::PreLinkThinLTO,
_ => llvm::OptStage::PreLinkNoLTO,
};
optimize_with_new_llvm_pass_manager(module, config, opt_level, opt_stage);
return Ok(());
}

// Create the two optimizing pass managers. These mirror what clang
// does, and are by populated by LLVM's default PassManagerBuilder.
// Each manager has a different set of passes, but they also share
Expand Down Expand Up @@ -757,24 +862,8 @@ pub unsafe fn with_llvm_pmb(
let opt_size =
config.opt_size.map(|x| to_llvm_opt_settings(x).1).unwrap_or(llvm::CodeGenOptSizeNone);
let inline_threshold = config.inline_threshold;

let pgo_gen_path = match config.pgo_gen {
SwitchWithOptPath::Enabled(ref opt_dir_path) => {
let path = if let Some(dir_path) = opt_dir_path {
dir_path.join("default_%m.profraw")
} else {
PathBuf::from("default_%m.profraw")
};

Some(CString::new(format!("{}", path.display())).unwrap())
}
SwitchWithOptPath::Disabled => None,
};

let pgo_use_path = config
.pgo_use
.as_ref()
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap());
let pgo_gen_path = get_pgo_gen_path(config);
let pgo_use_path = get_pgo_use_path(config);

llvm::LLVMRustConfigurePassManagerBuilder(
builder,
Expand Down
21 changes: 13 additions & 8 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,18 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
align: Align,
flags: MemFlags,
) {
let ptr_width = &self.sess().target.target.target_pointer_width;
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
let llintrinsicfn = self.get_intrinsic(&intrinsic_key);
let is_volatile = flags.contains(MemFlags::VOLATILE);
let ptr = self.pointercast(ptr, self.type_i8p());
let align = self.const_u32(align.bytes() as u32);
let volatile = self.const_bool(flags.contains(MemFlags::VOLATILE));
self.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None);
unsafe {
llvm::LLVMRustBuildMemSet(
self.llbuilder,
ptr,
align.bytes() as c_uint,
fill_byte,
size,
is_volatile,
);
}
}

fn select(
Expand Down Expand Up @@ -985,11 +990,11 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}

fn lifetime_start(&mut self, ptr: &'ll Value, size: Size) {
self.call_lifetime_intrinsic("llvm.lifetime.start", ptr, size);
self.call_lifetime_intrinsic("llvm.lifetime.start.p0i8", ptr, size);
}

fn lifetime_end(&mut self, ptr: &'ll Value, size: Size) {
self.call_lifetime_intrinsic("llvm.lifetime.end", ptr, size);
self.call_lifetime_intrinsic("llvm.lifetime.end.p0i8", ptr, size);
}

fn call(
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,6 @@ impl CodegenCx<'b, 'tcx> {
t_v8f64: t_f64, 8;
}

ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);

ifn!("llvm.trap", fn() -> void);
ifn!("llvm.debugtrap", fn() -> void);
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
Expand Down Expand Up @@ -830,8 +826,8 @@ impl CodegenCx<'b, 'tcx> {
ifn!("llvm.usub.sat.i64", fn(t_i64, t_i64) -> t_i64);
ifn!("llvm.usub.sat.i128", fn(t_i128, t_i128) -> t_i128);

ifn!("llvm.lifetime.start", fn(t_i64, i8p) -> void);
ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
ifn!("llvm.lifetime.start.p0i8", fn(t_i64, i8p) -> void);
ifn!("llvm.lifetime.end.p0i8", fn(t_i64, i8p) -> void);

ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
Expand Down
57 changes: 57 additions & 0 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,38 @@ pub enum CodeGenOptLevel {
Aggressive,
}

/// LLVMRustPassBuilderOptLevel
#[repr(C)]
pub enum PassBuilderOptLevel {
O0,
O1,
O2,
O3,
Os,
Oz,
}

/// LLVMRustOptStage
#[derive(PartialEq)]
#[repr(C)]
pub enum OptStage {
PreLinkNoLTO,
PreLinkThinLTO,
PreLinkFatLTO,
ThinLTO,
FatLTO,
}

/// LLVMRustSanitizerOptions
#[repr(C)]
pub struct SanitizerOptions {
pub sanitize_memory: bool,
pub sanitize_thread: bool,
pub sanitize_address: bool,
pub sanitize_recover: bool,
pub sanitize_memory_track_origins: c_int,
}

/// LLVMRelocMode
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
Expand Down Expand Up @@ -1316,6 +1348,14 @@ extern "C" {
Size: &'a Value,
IsVolatile: bool,
) -> &'a Value;
pub fn LLVMRustBuildMemSet(
B: &Builder<'a>,
Dst: &'a Value,
DstAlign: c_uint,
Val: &'a Value,
Size: &'a Value,
IsVolatile: bool,
) -> &'a Value;
pub fn LLVMBuildSelect(
B: &Builder<'a>,
If: &'a Value,
Expand Down Expand Up @@ -1889,6 +1929,23 @@ extern "C" {
Output: *const c_char,
FileType: FileType,
) -> LLVMRustResult;
pub fn LLVMRustOptimizeWithNewPassManager(
M: &'a Module,
TM: &'a TargetMachine,
OptLevel: PassBuilderOptLevel,
OptStage: OptStage,
NoPrepopulatePasses: bool,
VerifyIR: bool,
UseThinLTOBuffers: bool,
MergeFunctions: bool,
UnrollLoops: bool,
SLPVectorize: bool,
LoopVectorize: bool,
DisableSimplifyLibCalls: bool,
SanitizerOptions: Option<&SanitizerOptions>,
PGOGenPath: *const c_char,
PGOUsePath: *const c_char,
);
pub fn LLVMRustPrintModule(
M: &'a Module,
Output: *const c_char,
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct ModuleConfig {
pub vectorize_slp: bool,
pub merge_functions: bool,
pub inline_threshold: Option<usize>,
pub new_llvm_pass_manager: Option<bool>,
// Instead of creating an object file by doing LLVM codegen, just
// make the object file bitcode. Provides easy compatibility with
// emscripten's ecc compiler, when used as the linker.
Expand Down Expand Up @@ -132,6 +133,7 @@ impl ModuleConfig {
vectorize_slp: false,
merge_functions: false,
inline_threshold: None,
new_llvm_pass_manager: None,
}
}

Expand All @@ -140,6 +142,7 @@ impl ModuleConfig {
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
self.inline_threshold = sess.opts.cg.inline_threshold;
self.new_llvm_pass_manager = sess.opts.debugging_opts.new_llvm_pass_manager;
self.obj_is_bitcode =
sess.target.target.options.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled();
let embed_bitcode =
Expand Down
Loading