Skip to content

Commit

Permalink
svae work (ignore commit msgs they aren't foro anyone but myself :)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZelboK committed Jun 27, 2023
1 parent 0ca3e7a commit 6176cf2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_middle::ty::{self, Instance, EarlyBinder};
use rustc_session::config::DebugInfo;

use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx;

use super::metadata::file_metadata;
use super::util::DIB;
Expand Down
5 changes: 2 additions & 3 deletions crates/rustc_codegen_nvvm/src/debug_info/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def::CtorKind;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_index::Idx;
use rustc_index::vec::{Idx, IndexVec};
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::{self, GeneratorLayout};
use rustc_middle::ty::layout::{self, IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout};
use rustc_middle::ty::subst::GenericArgKind;
Expand Down Expand Up @@ -1677,7 +1676,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
fn field_name(&self, i: usize, cx: &CodegenCx<'_, 'tcx>) -> String {
let field_name = match *self {
VariantInfo::Adt(variant) if variant.ctor_kind() != Some(CtorKind::Fn) => {
Some(variant.fields[Idx::new(i)].ident(cx.tcx).name)
Some(variant.fields[usize::from_usize(i)].ident(cx.tcx).name)
}
VariantInfo::Generator {
generator_layout,
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_nvvm/src/debug_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_hir::def_id::{DefId, DefIdMap};
use rustc_index::vec::IndexVec;
use rustc_index::IndexVec;
use rustc_middle::mir;
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
Expand Down
33 changes: 21 additions & 12 deletions crates/rustc_codegen_nvvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
_ => bug!(),
};
self.call(
self.type_i1(),None,
self.type_i1(),
None,
None,
expect,
&[
Expand Down Expand Up @@ -367,16 +368,23 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
sym::ctlz | sym::cttz => {
let y = self.const_bool(false);
let llfn = self.get_intrinsic(&format!("llvm.{}.i{}", name, width));
self.call(self.type_i1(), None, llfn, &[args[0].immediate(), y], None)
self.call(self.type_i1(), None, None, llfn, &[args[0].immediate(), y], None)
}
sym::ctlz_nonzero | sym::cttz_nonzero => {
let y = self.const_bool(true);
let llvm_name = &format!("llvm.{}.i{}", &name_str[..4], width);
let llfn = self.get_intrinsic(llvm_name);
self.call(self.type_i1(), None,None, llfn, &[args[0].immediate(), y], None)
self.call(
self.type_i1(),
None,
None,
llfn,
&[args[0].immediate(), y],
None,
)
}
sym::ctpop => self.call(
self.type_i1(),
self.type_i1(),None,
None,
self.get_intrinsic(&format!("llvm.ctpop.i{}", width)),
&[args[0].immediate()],
Expand All @@ -387,7 +395,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
args[0].immediate() // byte swap a u8/i8 is just a no-op
} else {
self.call(
self.type_i1(),
self.type_i1(),None,
None,
self.get_intrinsic(&format!("llvm.bswap.i{}", width)),
&[args[0].immediate()],
Expand All @@ -396,7 +404,8 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
}
}
sym::bitreverse => self.call(
self.type_i1(),None,
self.type_i1(),
None,
None,
self.get_intrinsic(&format!("llvm.bitreverse.i{}", width)),
&[args[0].immediate()],
Expand All @@ -410,7 +419,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let llvm_name =
&format!("llvm.fsh{}.i{}", if is_left { 'l' } else { 'r' }, width);
let llfn = self.get_intrinsic(llvm_name);
self.call(self.type_i1(), None, llfn, &[val, val, raw_shift], None)
self.call(self.type_i1(), None,None, llfn, &[val, val, raw_shift], None)
}
sym::saturating_add | sym::saturating_sub => {
let is_add = name == sym::saturating_add;
Expand Down Expand Up @@ -463,7 +472,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let b_ptr = self.bitcast(b, i8p_ty);
let n = self.const_usize(layout.size().bytes());
let intrinsic = self.get_intrinsic("memcmp");
let cmp = self.call(self.type_i1(), None, intrinsic, &[a_ptr, b_ptr, n], None);
let cmp = self.call(self.type_i1(),None, None, intrinsic, &[a_ptr, b_ptr, n], None);
self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0))
}
}
Expand All @@ -488,7 +497,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn abort(&mut self) {
trace!("Generate abort call");
let fnname = self.get_intrinsic("llvm.trap");
self.call(self.type_i1(), None, fnname, &[], None);
self.call(self.type_i1(),None, None, fnname, &[], None);
}

fn assume(&mut self, val: Self::Value) {
Expand All @@ -501,7 +510,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
trace!("Generate expect call with `{:?}`, {}", cond, expected);
let expect = self.get_intrinsic("llvm.expect.i1");
self.call(
self.type_i1(),
self.type_i1(),None,
None,
expect,
&[cond, self.const_bool(expected)],
Expand All @@ -526,12 +535,12 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn va_start(&mut self, va_list: &'ll Value) -> Self::Value {
trace!("Generate va_start `{:?}`", va_list);
let intrinsic = self.cx().get_intrinsic("llvm.va_start");
self.call(self.type_i1(), None, intrinsic, &[va_list], None)
self.call(self.type_i1(),None, None, intrinsic, &[va_list], None)
}

fn va_end(&mut self, va_list: &'ll Value) -> Self::Value {
trace!("Generate va_end call `{:?}`", va_list);
let intrinsic = self.cx().get_intrinsic("llvm.va_end");
self.call(self.type_i1(), None, intrinsic, &[va_list], None)
self.call(self.type_i1(),None, None, intrinsic, &[va_list], None)
}
}
14 changes: 9 additions & 5 deletions crates/rustc_codegen_nvvm/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,21 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa
| NativeLibKind::RawDylib
| NativeLibKind::LinkArg
| NativeLibKind::Unspecified => continue,
NativeLibKind::WasmImportModule => todo!(),
}
// native libraries in cuda doesnt make much sense, extern functions
// do exist in nvvm for stuff like cuda syscalls and cuda provided functions
// but including libraries doesnt make sense because nvvm would have to translate
// the binary directly to ptx. We might want to add some way of linking in
// ptx files or custom bitcode modules as "libraries" perhaps in the future.
if let Some(name) = lib.name {
sess.err(format!(
"Adding native libraries to rlib is not supported in CUDA: {}",
name
));
match lib.name {
Some(name) => {
sess.err(format!(
"Adding native libraries to rlib is not supported in CUDA: {}",
name
));
}
_ => (),
}
}
trace!("Files linked in rlib:\n{:#?}", file_list);
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_nvvm/src/override_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ fn override_libm_function<'ll, 'tcx>(func: Instance<'tcx>, cx: &CodegenCx<'ll, '
let mut bx = Builder::build(cx, start);

let params = llvm::get_params(llfn);
let llcall = bx.call(cx.type_i1(), None, intrinsic, &params, None);
let llcall = bx.call(cx.type_i1(),None, None, intrinsic, &params, None);
bx.ret(llcall);
}

0 comments on commit 6176cf2

Please sign in to comment.