Skip to content

Commit 0eaa3e2

Browse files
committed
save
1 parent 6176cf2 commit 0eaa3e2

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

crates/rustc_codegen_nvvm/src/back.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::llvm::{self};
1+
use crate::llvm::{self, TargetMachine};
22
use crate::override_fns::define_or_override_fn;
33
use crate::{builder::Builder, context::CodegenCx, lto::ThinBuffer, LlvmMod, NvvmCodegenBackend};
44
use cstr::cstr;
@@ -105,7 +105,7 @@ pub fn target_machine_factory(
105105
.unwrap_or(sess.target.trap_unreachable);
106106

107107
Arc::new(move |_config: TargetMachineFactoryConfig| {
108-
let tm = unsafe {
108+
let tm: Option<&mut TargetMachine> = unsafe {
109109
llvm::LLVMRustCreateTargetMachine(
110110
triple.as_ptr(),
111111
std::ptr::null(),
@@ -121,6 +121,7 @@ pub fn target_machine_factory(
121121
false,
122122
)
123123
};
124+
124125
tm.ok_or_else(|| {
125126
format!(
126127
"Could not create LLVM TargetMachine for triple: {}",

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ use rustc_middle::ty::layout::{
1818
};
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
2020
use rustc_span::Span;
21+
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
2122
use rustc_target::abi::call::FnAbi;
22-
use rustc_target::abi::{self, AddressSpace, Align, Size, WrappingRange};
23+
use rustc_target::abi::{self, AddressSpace};
2324
use rustc_target::spec::{HasTargetSpec, Target};
2425
use std::borrow::Cow;
2526
use std::ffi::{CStr, CString};
@@ -998,7 +999,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
998999

9991000
fn set_personality_fn(&mut self, _personality: &'ll Value) {}
10001001

1001-
fn cleanup_landing_pad(&mut self, _: &'ll Value) -> &'ll Value {
1002+
fn cleanup_landing_pad(&mut self, _: &'ll Value)-> (Self::Value, Self::Value) {
10021003
todo!()
10031004
}
10041005

@@ -1134,6 +1135,38 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11341135
fn do_not_inline(&mut self, llret: &'ll Value) {
11351136
llvm::Attribute::NoInline.apply_callsite(llvm::AttributePlace::Function, llret);
11361137
}
1138+
1139+
fn to_immediate(&mut self, val: Self::Value, layout: TyAndLayout<'_>) -> Self::Value {
1140+
if let Abi::Scalar(scalar) = layout.abi {
1141+
self.to_immediate_scalar(val, scalar)
1142+
} else {
1143+
val
1144+
}
1145+
}
1146+
1147+
fn cast_float_to_int(
1148+
&mut self,
1149+
signed: bool,
1150+
x: Self::Value,
1151+
dest_ty: Self::Type,
1152+
) -> Self::Value {
1153+
let in_ty = self.cx().val_ty(x);
1154+
let (float_ty, int_ty) = if self.cx().type_kind(dest_ty) == TypeKind::Vector
1155+
&& self.cx().type_kind(in_ty) == TypeKind::Vector
1156+
{
1157+
(self.cx().element_type(in_ty), self.cx().element_type(dest_ty))
1158+
} else {
1159+
(in_ty, dest_ty)
1160+
};
1161+
assert!(matches!(self.cx().type_kind(float_ty), TypeKind::Float | TypeKind::Double));
1162+
assert_eq!(self.cx().type_kind(int_ty), TypeKind::Integer);
1163+
1164+
if let Some(false) = self.cx().sess().opts.unstable_opts.saturating_float_casts {
1165+
return if signed { self.fptosi(x, dest_ty) } else { self.fptoui(x, dest_ty) };
1166+
}
1167+
1168+
if signed { self.fptosi_sat(x, dest_ty) } else { self.fptoui_sat(x, dest_ty) }
1169+
}
11371170
}
11381171

11391172
impl<'a, 'll, 'tcx> StaticBuilderMethods for Builder<'a, 'll, 'tcx> {

crates/rustc_codegen_nvvm/src/debug_info/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_span::{FileNameDisplayPreference, DUMMY_SP};
2020
use rustc_target::abi::{Abi, Align, HasDataLayout, Integer, TagEncoding};
2121
use rustc_target::abi::{
2222
Primitive::{self, *},
23-
Size, VariantIdx, Variants,
23+
Size, VariantIdx, Variants, FieldIdx
2424
};
2525

2626
use crate::context::CodegenCx;
@@ -982,7 +982,7 @@ pub fn compile_unit_metadata<'ll>(
982982
_codegen_unit_name: &str,
983983
debug_context: &CrateDebugContext<'ll, '_>,
984984
) -> &'ll DIDescriptor {
985-
let name_in_debuginfo = match tcx.sess.local_crate_source_file {
985+
let name_in_debuginfo = match tcx.sess.local_crate_source_file() {
986986
Some(ref path) => path.clone(),
987987
None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()),
988988
};
@@ -1676,7 +1676,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
16761676
fn field_name(&self, i: usize, cx: &CodegenCx<'_, 'tcx>) -> String {
16771677
let field_name = match *self {
16781678
VariantInfo::Adt(variant) if variant.ctor_kind() != Some(CtorKind::Fn) => {
1679-
Some(variant.fields[usize::from_usize(i)].ident(cx.tcx).name)
1679+
Some(variant.fields[FieldIdx::from_usize(i)].ident(cx.tcx).name)
16801680
}
16811681
VariantInfo::Generator {
16821682
generator_layout,

crates/rustc_codegen_nvvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ impl WriteBackendMethods for NvvmCodegenBackend {
175175
type TargetMachine = &'static mut llvm::TargetMachine;
176176
type ThinData = ();
177177
type ThinBuffer = ThinBuffer;
178+
type TargetMachineError = &'static mut llvm::MyTargetMachineError; // fix later
178179

179180
fn run_link(
180181
_cgcx: &CodegenContext<Self>,
@@ -261,7 +262,6 @@ impl WriteBackendMethods for NvvmCodegenBackend {
261262
}
262263
}
263264

264-
type TargetMachineError;
265265

266266
// type TargetMachineError; // idk wtf im supposed to do with this but ill fix later
267267

crates/rustc_codegen_nvvm/src/link.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,10 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa
167167
// but including libraries doesnt make sense because nvvm would have to translate
168168
// the binary directly to ptx. We might want to add some way of linking in
169169
// ptx files or custom bitcode modules as "libraries" perhaps in the future.
170-
match lib.name {
171-
Some(name) => {
172-
sess.err(format!(
173-
"Adding native libraries to rlib is not supported in CUDA: {}",
174-
name
175-
));
176-
}
177-
_ => (),
178-
}
170+
sess.err(format!(
171+
"Adding native libraries to rlib is not supported in CUDA: {}",
172+
lib.name
173+
));
179174
}
180175
trace!("Files linked in rlib:\n{:#?}", file_list);
181176

crates/rustc_codegen_nvvm/src/llvm.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,23 @@ extern "C" {
491491
extern "C" {
492492
pub type TargetMachine;
493493
}
494+
extern "C" {
495+
pub type TargetMachineError;
496+
}
494497
extern "C" {
495498
pub(crate) type MemoryBuffer;
496499
}
497500

501+
pub struct MyTargetMachineError {
502+
inner: *mut TargetMachineError,
503+
}
504+
505+
impl std::fmt::Debug for MyTargetMachineError {
506+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
507+
write!(f, "MyTargetMachineError at {:p}", self.inner)
508+
}
509+
}
510+
498511
/// LLVMRustChecksumKind
499512
#[derive(Copy, Clone)]
500513
#[repr(C)]

0 commit comments

Comments
 (0)