Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
}
}

let cconv = self.llvm_cconv(&bx.cx);
let cconv = self.llvm_cconv(bx.cx);
if cconv != llvm::CCallConv {
llvm::SetInstructionCallConv(callsite, cconv);
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn create_wrapper_function<'ll>(
) {
let ty = cx.type_func(args, output.unwrap_or_else(|| cx.type_void()));
let llfn = declare_simple_fn(
&cx,
cx,
from_name,
llvm::CallConv::CCallConv,
llvm::UnnamedAddr::Global,
Expand Down Expand Up @@ -149,11 +149,11 @@ fn create_wrapper_function<'ll>(
}

let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
let mut bx = SBuilder::build(&cx, llbb);
let mut bx = SBuilder::build(cx, llbb);

if let Some(to_name) = to_name {
let callee = declare_simple_fn(
&cx,
cx,
to_name,
llvm::CallConv::CCallConv,
llvm::UnnamedAddr::Global,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn stackprotector_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll A
fn packed_stack_attr<'ll>(
cx: &SimpleCx<'ll>,
sess: &Session,
function_attributes: &Vec<TargetFeature>,
function_attributes: &[TargetFeature],
) -> Option<&'ll Attribute> {
if sess.target.arch != Arch::S390x {
return None;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ fn get_llvm_object_symbols(

unsafe extern "C" fn error_callback(error: *const c_char) -> *mut c_void {
let error = unsafe { CStr::from_ptr(error) };
Box::into_raw(Box::new(io::Error::new(
io::ErrorKind::Other,
format!("LLVM error: {}", error.to_string_lossy()),
)) as Box<io::Error>) as *mut c_void
Box::into_raw(Box::new(io::Error::other(format!(
"LLVM error: {}",
error.to_string_lossy()
)))) as *mut c_void
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/llvm_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
each_linked_rlib_for_lto: &[PathBuf],
modules: Vec<FatLtoInput<Self>>,
) -> CompiledModule {
let mut module = back::lto::run_fat(
let module = back::lto::run_fat(
cgcx,
&sess.prof,
shared_emitter,
Expand All @@ -117,7 +117,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {

let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
let dcx = dcx.handle();
back::lto::run_pass_manager(cgcx, &sess.prof, dcx, &mut module, false);
back::lto::run_pass_manager(cgcx, &sess.prof, dcx, &module, false);

back::write::codegen(cgcx, &sess.prof, shared_emitter, module, &cgcx.module_config)
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl CodegenBackend for LlvmCodegenBackend {
llvm::build_string(|s| unsafe { llvm::LLVMRustPrintStatisticsJSON(s) }).unwrap();

if !llvm_stats_json.is_empty() {
if let Err(e) = std::fs::write(&out_path, llvm_stats_json) {
if let Err(e) = std::fs::write(out_path, llvm_stats_json) {
sess.dcx().err(format!("failed to write stats to {out_path}: {e}"));
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ fn prepare_lto(
let mut upstream_modules = Vec::new();
for path in each_linked_rlib_for_lto {
let archive_data = unsafe {
Mmap::map(std::fs::File::open(&path).expect("couldn't open rlib"))
Mmap::map(std::fs::File::open(path).expect("couldn't open rlib"))
.expect("couldn't map rlib")
};
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
let metadata_link =
rmeta_link::read(&archive, &archive_data, &path, cgcx.target_is_like_aix).unwrap();
rmeta_link::read(&archive, &archive_data, path, cgcx.target_is_like_aix).unwrap();
let obj_files = archive
.members()
.filter_map(|child| {
Expand Down Expand Up @@ -465,7 +465,7 @@ fn thin_lto(
incr_comp_session.new_session_directory.join(THIN_LTO_KEYS_INCR_COMP_FILE_NAME)
});

let prev_key_map = if let Some(ref old_incr_comp_session_dir) = incr_comp_session
let prev_key_map = if let Some(old_incr_comp_session_dir) = incr_comp_session
.and_then(|incr_comp_session| incr_comp_session.old_session_directory.as_deref())
{
let old_path = old_incr_comp_session_dir.join(THIN_LTO_KEYS_INCR_COMP_FILE_NAME);
Expand Down Expand Up @@ -548,7 +548,7 @@ pub(crate) fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
}
config::AutoDiff::PrintTAFn(fun) => {
enzyme.set_print_type(true); // Enable general type printing
enzyme.set_print_type_fun(&fun); // Set specific function to analyze
enzyme.set_print_type_fun(fun); // Set specific function to analyze
}
config::AutoDiff::Inline => {
enzyme.set_inline(true);
Expand Down
22 changes: 10 additions & 12 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub(crate) fn save_temp_bitcode(
}

fn write_bitcode_to_file(module: &ModuleLlvm, path: &Path) {
let path = path_to_c_string(&path);
let path = path_to_c_string(path);
module.with_module_refs(|ModuleRefs { llmod, .. }| {
unsafe { llvm::LLVMWriteBitcodeToFile(llmod, path.as_ptr()) };
});
Expand Down Expand Up @@ -669,7 +669,7 @@ pub(crate) unsafe fn llvm_optimize<'ll>(
}

// Create the new parameter list, with ptr as the first argument
let mut new_param_types = Vec::with_capacity(old_param_count as usize + 1);
let mut new_param_types = Vec::with_capacity(old_param_count + 1);
new_param_types.push(cx.type_ptr());

// This relies on undocumented LLVM knowledge that scalars must be passed as i64
Expand All @@ -689,7 +689,7 @@ pub(crate) unsafe fn llvm_optimize<'ll>(

// Create the new function, with a temporary .offload name to avoid a name collision.
let old_fn_name = String::from_utf8(llvm::get_value_name(old_fn)).unwrap();
let new_fn_name = format!("{}.offload", &old_fn_name);
let new_fn_name = format!("{old_fn_name}.offload");
let new_fn = cx.add_func(&new_fn_name, new_fn_ty);
let a0 = llvm::get_param(new_fn, 0);
llvm::set_value_name(a0, CString::new("dyn_ptr").unwrap().as_bytes());
Expand Down Expand Up @@ -1026,7 +1026,7 @@ pub(crate) fn codegen(
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
let thin_bc =
module.module_llvm.thin_lto_buffer.get().expect("cannot find embedded bitcode");
embed_bitcode(cgcx, llcx, llmod, &thin_bc);
embed_bitcode(cgcx, llcx, llmod, thin_bc);
}
}

Expand All @@ -1043,14 +1043,12 @@ pub(crate) fn codegen(
output_ptr: *mut c_char,
output_len: size_t,
) -> size_t {
let input =
unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };
let input = unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len) };

let Ok(input) = str::from_utf8(input) else { return 0 };

let output = unsafe {
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
};
let output =
unsafe { slice::from_raw_parts_mut(output_ptr as *mut u8, output_len) };
let mut cursor = io::Cursor::new(output);

let Ok(demangled) = rustc_demangle::try_demangle(input) else { return 0 };
Expand Down Expand Up @@ -1183,15 +1181,15 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
if byte == b'\\' || byte == b'"' {
asm.push(b'\\');
asm.push(byte);
} else if byte < 0x20 || byte >= 0x80 {
} else if (0x20..0x80).contains(&byte) {
asm.push(byte);
} else {
// Avoid non UTF-8 inline assembly. Use octal escape sequence, because it is fixed
// width, while hex escapes will consume following characters.
asm.push(b'\\');
asm.push(b'0' + ((byte >> 6) & 0x7));
asm.push(b'0' + ((byte >> 3) & 0x7));
asm.push(b'0' + ((byte >> 0) & 0x7));
} else {
asm.push(byte);
}
}
asm.extend_from_slice(b"\"\n");
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,18 @@ impl<'a, 'll> SBuilder<'a, 'll> {
bundles.push(funclet_bundle);
}

let call = unsafe {
unsafe {
llvm::LLVMBuildCallWithOperandBundles(
self.llbuilder(),
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.as_ptr(),
args.len() as c_uint,
bundles.as_ptr(),
bundles.len() as c_uint,
c"".as_ptr(),
)
};
call
}
}
}

Expand Down Expand Up @@ -154,8 +153,8 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
// Cast to default addrspace if necessary
llvm::LLVMBuildPointerCast(self.llbuilder(), alloca, self.cx.type_ptr(), UNNAMED)
};
if name != "" {
llvm::set_value_name(val, &name.as_bytes());
if !name.is_empty() {
llvm::set_value_name(val, name.as_bytes());
}
val
}
Expand Down Expand Up @@ -1480,7 +1479,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
self.llbuilder(),
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.as_ptr(),
args.len() as c_uint,
bundles.as_ptr(),
bundles.len() as c_uint,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/builder/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
if let rustc_abi::BackendRepr::ScalarPair { a: _, b: _, b_offset: _ } =
layout.backend_repr()
{
new_activities.push(da[i].clone());
new_activities.push(da[i]);
new_positions.push(i + 1 - del_activities);
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
let global_dupnoneedv = cx.declare_global("enzyme_dupnoneedv", cx.type_ptr());

while activity_pos < inputs.len() {
let diff_activity = inputs[activity_pos as usize];
let diff_activity = inputs[activity_pos];
// Duplicated arguments received a shadow argument, into which enzyme will write the
// gradient.
let (activity, duplicated): (&Value, bool) = match diff_activity {
Expand Down Expand Up @@ -346,7 +346,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
enzyme_ty,
);

let num_args = llvm::LLVMCountParams(&fn_to_diff);
let num_args = llvm::LLVMCountParams(fn_to_diff);
let mut args = Vec::with_capacity(num_args as usize + 1);
args.push(fn_to_diff);

Expand All @@ -363,7 +363,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
match_args_from_caller_to_enzyme(bx, attrs.width, &mut args, &attrs.input_activity, fn_args);

if !fnc_tree.args.is_empty() || !fnc_tree.ret.0.is_empty() {
crate::typetree::add_tt(&bx, fn_to_diff, fnc_tree);
crate::typetree::add_tt(bx, fn_to_diff, fnc_tree);
}

let call = bx.call(enzyme_ty, None, None, ad_fn, ReturnSlot::Direct, &args, None, None);
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (&'ll llvm::Value, llvm::T
let args = vec![tptr, ti64, ti32, ti32, tptr, tptr];
let tgt_fn_ty = cx.type_func(&args, ti32);
let name = "__tgt_target_kernel";
let tgt_decl = declare_offload_fn(&cx, name, tgt_fn_ty);
let tgt_decl = declare_offload_fn(cx, name, tgt_fn_ty);
let nounwind = llvm::AttributeKind::NoUnwind.create_attr(cx.llcx);
attributes::apply_to_llfn(tgt_decl, Function, &[nounwind]);
(tgt_decl, tgt_fn_ty)
Expand All @@ -141,7 +141,7 @@ pub(crate) fn declare_omp_get_num_devices<'ll>(
let ti32 = cx.type_i32();
let tgt_fn_ty = cx.type_func(&[], ti32);
let name = "omp_get_num_devices";
let tgt_decl = declare_offload_fn(&cx, name, tgt_fn_ty);
let tgt_decl = declare_offload_fn(cx, name, tgt_fn_ty);
let nounwind = llvm::AttributeKind::NoUnwind.create_attr(cx.llcx);
attributes::apply_to_llfn(tgt_decl, Function, &[nounwind]);
(tgt_decl, tgt_fn_ty)
Expand All @@ -157,7 +157,7 @@ pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll llvm::Value
let c_entry_name = CString::new(unknown_txt).unwrap();
let c_val = c_entry_name.as_bytes_with_nul();
let initializer = crate::common::bytes_in_context(cx.llcx, c_val);
let at_zero = add_unnamed_global(&cx, &"", initializer, PrivateLinkage);
let at_zero = add_unnamed_global(cx, "", initializer, PrivateLinkage);
llvm::set_alignment(at_zero, Align::ONE);

// @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8
Expand All @@ -171,8 +171,8 @@ pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll llvm::Value
];
let struct_elems_ty: Vec<_> = struct_elems.iter().map(|&x| cx.val_ty(x)).collect();
let initializer = crate::common::named_struct(struct_ident_ty, &struct_elems);
cx.set_struct_body(struct_ident_ty, &struct_elems_ty, false);
let at_one = add_unnamed_global(&cx, &"", initializer, PrivateLinkage);
cx.set_struct_body(struct_ident_ty, &struct_elems_ty);
let at_one = add_unnamed_global(cx, "", initializer, PrivateLinkage);
llvm::set_alignment(at_one, Align::EIGHT);
at_one
}
Expand All @@ -199,7 +199,7 @@ impl TgtOffloadEntry {
// For each kernel to run on the gpu, we will later generate one entry of this type.
// copied from LLVM
let entry_elements = vec![ti64, ti16, ti16, ti32, tptr, tptr, ti64, ti64, tptr];
cx.set_struct_body(offload_entry_ty, &entry_elements, false);
cx.set_struct_body(offload_entry_ty, &entry_elements);
offload_entry_ty
}

Expand Down Expand Up @@ -355,9 +355,9 @@ fn gen_tgt_data_mappers<'ll>(
let mapper_begin = "__tgt_target_data_begin_mapper";
let mapper_update = "__tgt_target_data_update_mapper";
let mapper_end = "__tgt_target_data_end_mapper";
let begin_mapper_decl = declare_offload_fn(&cx, mapper_begin, mapper_fn_ty);
let update_mapper_decl = declare_offload_fn(&cx, mapper_update, mapper_fn_ty);
let end_mapper_decl = declare_offload_fn(&cx, mapper_end, mapper_fn_ty);
let begin_mapper_decl = declare_offload_fn(cx, mapper_begin, mapper_fn_ty);
let update_mapper_decl = declare_offload_fn(cx, mapper_update, mapper_fn_ty);
let end_mapper_decl = declare_offload_fn(cx, mapper_end, mapper_fn_ty);

let nounwind = llvm::AttributeKind::NoUnwind.create_attr(cx.llcx);
attributes::apply_to_llfn(begin_mapper_decl, Function, &[nounwind]);
Expand Down Expand Up @@ -455,34 +455,34 @@ pub(crate) fn gen_define_handling<'ll>(
})
.collect::<Vec<_>>();
let offload_sizes =
add_priv_unnamed_arr(&cx, &format!(".offload_sizes.{symbol}"), &actual_sizes);
add_priv_unnamed_arr(cx, &format!(".offload_sizes.{symbol}"), &actual_sizes);
let memtransfer_begin =
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.begin"), &transfer_to);
add_priv_unnamed_arr(cx, &format!(".offload_maptypes.{symbol}.begin"), &transfer_to);
let memtransfer_kernel =
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.kernel"), &transfer_kernel);
add_priv_unnamed_arr(cx, &format!(".offload_maptypes.{symbol}.kernel"), &transfer_kernel);
let memtransfer_end =
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.end"), &transfer_from);
add_priv_unnamed_arr(cx, &format!(".offload_maptypes.{symbol}.end"), &transfer_from);

// Next: For each function, generate these three entries. A weak constant,
// the llvm.rodata entry name, and the llvm_offload_entries value

let name = format!(".{symbol}.region_id");
let initializer = cx.get_const_i8(0);
let region_id = add_global(&cx, &name, initializer, WeakAnyLinkage);
let region_id = add_global(cx, &name, initializer, WeakAnyLinkage);

let c_entry_name = CString::new(symbol.clone()).unwrap();
let c_val = c_entry_name.as_bytes_with_nul();
let offload_entry_name = format!(".offloading.entry_name.{symbol}");

let initializer = crate::common::bytes_in_context(cx.llcx, c_val);
let llglobal = add_unnamed_global(&cx, &offload_entry_name, initializer, InternalLinkage);
let llglobal = add_unnamed_global(cx, &offload_entry_name, initializer, InternalLinkage);
llvm::set_alignment(llglobal, Align::ONE);
llvm::set_section(llglobal, c".llvm.rodata.offloading");

let name = format!(".offloading.entry.{symbol}");

// See the __tgt_offload_entry documentation above.
let elems = TgtOffloadEntry::new(&cx, region_id, llglobal);
let elems = TgtOffloadEntry::new(cx, region_id, llglobal);

let initializer = crate::common::named_struct(offload_entry_ty, &elems);
let c_name = CString::new(name).unwrap();
Expand Down Expand Up @@ -735,7 +735,7 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>(
s_ident_t,
);
let values = KernelArgsTy::new(
&cx,
cx,
num_args,
memtransfer_kernel,
geps,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
}

fn const_i64(&self, i: i64) -> &'ll Value {
self.const_int(self.type_i64(), i as i64)
self.const_int(self.type_i64(), i)
}

fn const_int(&self, t: Type<'ll>, i: i64) -> &'ll Value {
Expand Down
Loading
Loading