Skip to content

Commit a9f62a4

Browse files
committed
Add -Z llvm-opt-bisect-limit-cgu
1 parent d388bfe commit a9f62a4

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*.log
12
/const_prop_slice_pat_ice
23
/*.txt
34
# This file should only ignore things that are generated during a `x.py` build,

bisect.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export RUSTFLAGS_NOT_BOOTSTRAP="-C llvm-args=-opt-bisect-limit=-1 -Z llvm-opt-bisect-limit-cgu=rustc_mir_build.63d28fcded2a05ed-cgu.007"
2+
./x build --stage 2 library --keep-stage 0 --keep-stage-std 1 2> build.log
3+
./build/host/stage2/bin/rustc ./tests/ui/consts/const_prop_slice_pat_ice.rs

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ impl ModuleLlvm {
415415
fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
416416
unsafe {
417417
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
418+
if let Some(ref only_cgu) = tcx.sess.opts.unstable_opts.llvm_opt_bisect_limit_cgu {
419+
if mod_name != only_cgu {
420+
llvm::LLVMRustContextSetSetRunAllOptPassGate(llcx);
421+
} else {
422+
eprintln!("opt-bisect-only: {}", only_cgu);
423+
}
424+
}
418425
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
419426
ModuleLlvm { llmod_raw, llcx, tm: create_target_machine(tcx, mod_name) }
420427
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,4 +2381,6 @@ extern "C" {
23812381
callback: GetSymbolsCallback,
23822382
error_callback: GetSymbolsErrorCallback,
23832383
) -> *mut c_void;
2384+
2385+
pub fn LLVMRustContextSetSetRunAllOptPassGate(context: &Context);
23842386
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#include "llvm/IR/IntrinsicsARM.h"
1111
#include "llvm/IR/LLVMRemarkStreamer.h"
1212
#include "llvm/IR/Mangler.h"
13+
#include "llvm/IR/OptBisect.h"
1314
#include "llvm/Remarks/RemarkStreamer.h"
1415
#include "llvm/Remarks/RemarkSerializer.h"
1516
#include "llvm/Remarks/RemarkFormat.h"
1617
#include "llvm/Support/ToolOutputFile.h"
18+
#include <llvm/IR/LLVMContext.h>
1719
#if LLVM_VERSION_GE(16, 0)
1820
#include "llvm/Support/ModRef.h"
1921
#endif
@@ -2060,3 +2062,19 @@ extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
20602062
return false;
20612063
#endif
20622064
}
2065+
2066+
struct RunAllOptPassGate : public OptPassGate {
2067+
bool shouldRunPass(const StringRef PassName, StringRef IRDescription) override {
2068+
return true;
2069+
}
2070+
bool isEnabled() const override { return true; }
2071+
};
2072+
2073+
static RunAllOptPassGate &getRunAllOptPassGate() {
2074+
static RunAllOptPassGate RunAllOptPassGate;
2075+
return RunAllOptPassGate;
2076+
}
2077+
2078+
extern "C" void LLVMRustContextSetSetRunAllOptPassGate(LLVMContextRef C) {
2079+
unwrap(C)->setOptPassGate(getRunAllOptPassGate());
2080+
}

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,8 @@ options! {
15851585
"link native libraries in the linker invocation (default: yes)"),
15861586
link_only: bool = (false, parse_bool, [TRACKED],
15871587
"link the `.rlink` file generated by `-Z no-link` (default: no)"),
1588+
llvm_opt_bisect_limit_cgu: Option<String> = (None, parse_opt_string, [UNTRACKED],
1589+
"apply -opt-bisect-limit to the specified cgu"),
15881590
llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
15891591
"a list LLVM plugins to enable (space separated)"),
15901592
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
./x build --stage 2 library
1+
./x build --stage 2 library 2> build.log
22
./build/host/stage2/bin/rustc ./tests/ui/consts/const_prop_slice_pat_ice.rs

0 commit comments

Comments
 (0)