Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

remove unnecessary heap allocation #728

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
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
59 changes: 29 additions & 30 deletions compiler/llvm/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,81 +17,81 @@ pub fn init(options: &Options) {
);
}

let mut args = options
let args = options
.codegen_opts
.llvm_args
.iter()
.map(|arg| CString::new(arg.as_str()).unwrap())
.collect::<Vec<_>>();

let mut ptrs = args.iter().map(|cstr| cstr.as_ptr()).collect::<Vec<_>>();

// MLIR
if options.debugging_opts.time_mlir_passes {
args.push(CString::new("-mlir-timing").unwrap());
args.push(CString::new("-mlir-timing-display=tree").unwrap());
ptrs.push("-mlir-timing\0".as_ptr() as _);
ptrs.push("-mlir-timing-display=tree\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_passes_before {
args.push(CString::new("-mlir-print-ir-before-all").unwrap());
args.push(CString::new("-print-before-all").unwrap());
ptrs.push("-mlir-print-ir-before-all\0".as_ptr() as _);
ptrs.push("-print-before-all\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_passes_after {
args.push(CString::new("-mlir-print-ir-after-all").unwrap());
args.push(CString::new("-print-after-all").unwrap());
ptrs.push("-mlir-print-ir-after-all\0".as_ptr() as _);
ptrs.push("-print-after-all\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_passes_on_change {
args.push(CString::new("-mlir-print-ir-after-change").unwrap());
args.push(CString::new("-print-changed").unwrap());
ptrs.push("-mlir-print-ir-after-change\0".as_ptr() as _);
ptrs.push("-print-changed\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_passes_on_failure {
args.push(CString::new("-mlir-print-ir-after-failure").unwrap());
ptrs.push("-mlir-print-ir-after-failure\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_module_scope {
args.push(CString::new("-mlir-print-ir-module-scope").unwrap());
args.push(CString::new("-print-module-scope").unwrap());
ptrs.push("-mlir-print-ir-module-scope\0".as_ptr() as _);
ptrs.push("-print-module-scope\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_local_scope {
args.push(CString::new("-mlir-print-local-scope").unwrap());
ptrs.push("-mlir-print-local-scope\0".as_ptr() as _);
}
if options.debugging_opts.mlir_enable_statistics {
args.push(CString::new("-mlir-pass-statistics").unwrap());
ptrs.push("-mlir-pass-statistics\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_op_on_diagnostic {
args.push(CString::new("-mlir-print-op-on-diagnostic").unwrap());
ptrs.push("-mlir-print-op-on-diagnostic\0".as_ptr() as _);
}
if options.debugging_opts.mlir_print_trace_on_diagnostic {
args.push(CString::new("-mlir-print-stacktrace-on-diagnostic").unwrap());
ptrs.push("-mlir-print-stacktrace-on-diagnostic\0".as_ptr() as _);
}
if let Some(path) = options
.debugging_opts
.mlir_enable_crash_reproducer
.as_deref()
{
args.push(
CString::new(format!(
"-mlir-pass-pipeline-crash-reproducer={}",
ptrs.push(format!(
"-mlir-pass-pipeline-crash-reproducer={}\0",
path.display()
))
.unwrap(),
).as_ptr() as _,
);
}
match options.debugging_opts.mlir_print_debug_info {
MlirDebugPrinting::Plain => {
args.push(CString::new("-mlir-print-debuginfo").unwrap());
ptrs.push("-mlir-print-debuginfo\0".as_ptr() as _);
}
MlirDebugPrinting::Pretty => {
args.push(CString::new("-mlir-print-debuginfo").unwrap());
args.push(CString::new("-mlir-pretty-debuginfo").unwrap());
ptrs.push("-mlir-print-debuginfo\0".as_ptr() as _);
ptrs.push("-mlir-pretty-debuginfo\0".as_ptr() as _);
}
_ => (),
}
if options.debugging_opts.mlir_print_generic_ops {
args.push(CString::new("-mlir-print-op-generic").unwrap());
ptrs.push("-mlir-print-op-generic\0".as_ptr() as _);
} else {
args.push(CString::new("-mlir-print-assume-verified").unwrap());
ptrs.push("-mlir-print-assume-verified\0".as_ptr() as _);
}

// LLVM
if options.debugging_opts.time_llvm_passes {
args.push(CString::new("-time-passes").unwrap());
ptrs.push("-time-passes\0".as_ptr() as _);
}
match options
.codegen_opts
Expand All @@ -100,15 +100,14 @@ pub fn init(options: &Options) {
{
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
args.push(CString::new("-mergefunc-use-aliases").unwrap());
ptrs.push("-mergefunc-use-aliases\0".as_ptr() as _);
}
}

// HACK: LLVM inserts `llvm.assume` calls to preserve align attributes
// during inlining. Unfortunately these may block other optimizations.
args.push(CString::new("-preserve-alignment-assumptions-during-inlining=false").unwrap());
ptrs.push("-preserve-alignment-assumptions-during-inlining=false\0".as_ptr() as _);

let ptrs = args.iter().map(|cstr| cstr.as_ptr()).collect::<Vec<_>>();
let overview = std::ptr::null();

unsafe {
Expand Down