Skip to content

Commit d74b402

Browse files
committed
Auto merge of rust-lang#55281 - alexcrichton:revert-demote, r=petrochenkov
Revert "rustc: Fix (again) simd vectors by-val in ABI" This reverts commit 3cc8f73.
2 parents 7cfe5de + 086f5a5 commit d74b402

File tree

9 files changed

+9
-332
lines changed

9 files changed

+9
-332
lines changed

src/librustc_codegen_llvm/back/lto.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ impl LtoModuleCodegen {
8080
let module = module.take().unwrap();
8181
{
8282
let config = cgcx.config(module.kind);
83-
run_pass_manager(cgcx, &module, config, false);
83+
let llmod = module.module_llvm.llmod();
84+
let tm = &*module.module_llvm.tm;
85+
run_pass_manager(cgcx, tm, llmod, config, false);
8486
timeline.record("fat-done");
8587
}
8688
Ok(module)
@@ -555,7 +557,8 @@ fn thin_lto(cgcx: &CodegenContext,
555557
}
556558

557559
fn run_pass_manager(cgcx: &CodegenContext,
558-
module: &ModuleCodegen,
560+
tm: &llvm::TargetMachine,
561+
llmod: &llvm::Module,
559562
config: &ModuleConfig,
560563
thin: bool) {
561564
// Now we have one massive module inside of llmod. Time to run the
@@ -566,8 +569,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
566569
debug!("running the pass manager");
567570
unsafe {
568571
let pm = llvm::LLVMCreatePassManager();
569-
let llmod = module.module_llvm.llmod();
570-
llvm::LLVMRustAddAnalysisPasses(module.module_llvm.tm, pm, llmod);
572+
llvm::LLVMRustAddAnalysisPasses(tm, pm, llmod);
571573

572574
if config.verify_llvm_ir {
573575
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
@@ -862,7 +864,7 @@ impl ThinModule {
862864
// little differently.
863865
info!("running thin lto passes over {}", module.name);
864866
let config = cgcx.config(module.kind);
865-
run_pass_manager(cgcx, &module, config, true);
867+
run_pass_manager(cgcx, module.module_llvm.tm, llmod, config, true);
866868
cgcx.save_temp_bitcode(&module, "thin-lto-after-pm");
867869
timeline.record("thin-done");
868870
}

src/librustc_codegen_llvm/back/write.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
633633
None,
634634
&format!("llvm module passes [{}]", module_name.unwrap()),
635635
|| {
636-
llvm::LLVMRunPassManager(mpm, llmod);
636+
llvm::LLVMRunPassManager(mpm, llmod)
637637
});
638638

639639
// Deallocate managers that we're now done with
@@ -691,38 +691,6 @@ unsafe fn codegen(cgcx: &CodegenContext,
691691
create_msvc_imps(cgcx, llcx, llmod);
692692
}
693693

694-
// Ok now this one's a super interesting invocations. SIMD in rustc is
695-
// difficult where we want some parts of the program to be able to use
696-
// some SIMD features while other parts of the program don't. The real
697-
// tough part is that we want this to actually work correctly!
698-
//
699-
// We go to great lengths to make sure this works, and one crucial
700-
// aspect is that vector arguments (simd types) are never passed by
701-
// value in the ABI of functions. It turns out, however, that LLVM will
702-
// undo our "clever work" of passing vector types by reference. Its
703-
// argument promotion pass will promote these by-ref arguments to
704-
// by-val. That, however, introduces codegen errors!
705-
//
706-
// The upstream LLVM bug [1] has unfortunatey not really seen a lot of
707-
// activity. The Rust bug [2], however, has seen quite a lot of reports
708-
// of this in the wild. As a result, this is worked around locally here.
709-
// We have a custom transformation, `LLVMRustDemoteSimdArguments`, which
710-
// does the opposite of argument promotion by demoting any by-value SIMD
711-
// arguments in function signatures to pointers intead of being
712-
// by-value.
713-
//
714-
// This operates at the LLVM IR layer because LLVM is thwarting our
715-
// codegen and this is the only chance we get to make sure it's correct
716-
// before we hit codegen.
717-
//
718-
// Hopefully one day the upstream LLVM bug will be fixed and we'll no
719-
// longer need this!
720-
//
721-
// [1]: https://bugs.llvm.org/show_bug.cgi?id=37358
722-
// [2]: https://github.com/rust-lang/rust/issues/50154
723-
llvm::LLVMRustDemoteSimdArguments(llmod);
724-
cgcx.save_temp_bitcode(&module, "simd-demoted");
725-
726694
// A codegen-specific pass manager is used to generate object
727695
// files for an LLVM module.
728696
//

src/librustc_codegen_llvm/llvm/ffi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1138,8 +1138,6 @@ extern "C" {
11381138
/// Runs a pass manager on a module.
11391139
pub fn LLVMRunPassManager(PM: &PassManager<'a>, M: &'a Module) -> Bool;
11401140

1141-
pub fn LLVMRustDemoteSimdArguments(M: &'a Module);
1142-
11431141
pub fn LLVMInitializePasses();
11441142

11451143
pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;

src/librustc_llvm/build.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ fn main() {
162162
}
163163

164164
build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));
165-
cfg
166-
.file("../rustllvm/DemoteSimd.cpp")
167-
.file("../rustllvm/PassWrapper.cpp")
165+
cfg.file("../rustllvm/PassWrapper.cpp")
168166
.file("../rustllvm/RustWrapper.cpp")
169167
.file("../rustllvm/ArchiveWrapper.cpp")
170168
.file("../rustllvm/Linker.cpp")

src/rustllvm/DemoteSimd.cpp

-189
This file was deleted.

src/test/run-make/simd-argument-promotion-thwarted/Makefile

-13
This file was deleted.

src/test/run-make/simd-argument-promotion-thwarted/t1.rs

-21
This file was deleted.

src/test/run-make/simd-argument-promotion-thwarted/t2.rs

-14
This file was deleted.

0 commit comments

Comments
 (0)