Skip to content

Commit 0ca3e7a

Browse files
committed
save work
1 parent 0ff6d48 commit 0ca3e7a

File tree

11 files changed

+51
-34
lines changed

11 files changed

+51
-34
lines changed

crates/rustc_codegen_nvvm/src/asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub(crate) fn inline_asm_call<'a, 'll, 'tcx>(
302302
dia,
303303
);
304304
let call = bx.call(fty,
305+
None,
305306
None,
306307
v,
307308
inputs, None);

crates/rustc_codegen_nvvm/src/back.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_codegen_ssa::{
1313
CompiledModule, ModuleCodegen, ModuleKind,
1414
};
1515
use rustc_data_structures::small_c_str::SmallCStr;
16-
use rustc_errors::{FatalError, Handler, DiagnosticMessage, DiagnosticBuilder};
16+
use rustc_errors::{FatalError, Handler};
1717
use rustc_fs_util::path_to_c_string;
1818
use rustc_middle::bug;
1919
use rustc_middle::mir::mono::MonoItem;

crates/rustc_codegen_nvvm/src/builder.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_codegen_ssa::traits::BackendTypes;
1212
use rustc_codegen_ssa::traits::*;
1313
use rustc_codegen_ssa::MemFlags;
1414
use rustc_hir::def_id::DefId;
15+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1516
use rustc_middle::ty::layout::{
1617
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
1718
};
@@ -269,6 +270,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
269270
fn invoke(
270271
&mut self,
271272
ty: &'ll Type,
273+
fn_attrs: Option<&CodegenFnAttrs>,
272274
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
273275
llfn: &'ll Value,
274276
args: &[&'ll Value],
@@ -277,7 +279,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
277279
funclet: Option<&()>,
278280
) -> &'ll Value {
279281
trace!("invoke");
280-
let call = self.call(ty, None, llfn, args, funclet);
282+
let call = self.call(ty, None, None, llfn, args, funclet);
281283
// exceptions arent a thing, go directly to the `then` block
282284
unsafe { llvm::LLVMBuildBr(self.llbuilder, then) };
283285
call
@@ -436,7 +438,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
436438
let intrinsic = self.get_intrinsic(name);
437439
// call actually ignores the ty param for now, we just need it for conformance with nightly api
438440
// so give it a dummy type
439-
let res = self.call(self.type_i1(), None, intrinsic, &[lhs, rhs], None);
441+
let res = self.call(self.type_i1(), None,None, intrinsic, &[lhs, rhs], None);
440442
(self.extract_value(res, 0), self.extract_value(res, 1))
441443
}
442444

@@ -518,7 +520,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
518520
// self.call(vprintf, &[formatlist, valist], None);
519521

520522
let trap = self.get_intrinsic("llvm.trap");
521-
self.call(ty, None, trap, &[], None);
523+
self.call(ty, None,None, trap, &[], None);
522524
unsafe { llvm::LLVMBuildLoad(self.llbuilder, ptr, unnamed()) }
523525
}
524526

@@ -996,15 +998,15 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
996998

997999
fn set_personality_fn(&mut self, _personality: &'ll Value) {}
9981000

999-
fn cleanup_landing_pad(&mut self, _: &'ll Type, _: &'ll Value) -> &'ll Value {
1001+
fn cleanup_landing_pad(&mut self, _: &'ll Value) -> &'ll Value {
10001002
todo!()
10011003
}
10021004

10031005
fn filter_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value) {
10041006
todo!()
10051007
}
10061008

1007-
fn resume(&mut self, _exn: &'ll Value) {
1009+
fn resume(&mut self, _exn: &'ll Value, _exn1: &'ll Value) {
10081010
self.unsupported("resumes");
10091011
}
10101012

@@ -1090,6 +1092,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10901092
fn call(
10911093
&mut self,
10921094
_: &'ll Type,
1095+
fn_attrs: Option<&CodegenFnAttrs>,
10931096
_fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
10941097
llfn: &'ll Value,
10951098
args: &[&'ll Value],
@@ -1263,6 +1266,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
12631266
self.call(
12641267
self.type_i1(),
12651268
None,
1269+
None,
12661270
lifetime_intrinsic,
12671271
&[self.cx.const_u64(size), ptr],
12681272
None,

crates/rustc_codegen_nvvm/src/const_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use abi::Primitive::Pointer;
44
use libc::c_uint;
55
use rustc_ast::Mutability;
66
use rustc_codegen_ssa::{
7-
mir::place::PlaceRef,
87
traits::{BaseTypeMethods,
98
ConstMethods, DerivedTypeMethods, MiscMethods, StaticMethods},
109
};
10+
use rustc_codegen_ssa::mir::place::PlaceRef;
1111
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
1212
use rustc_middle::ty::layout::LayoutOf;
1313
use rustc_middle::ty::{layout::TyAndLayout, ScalarInt};

crates/rustc_codegen_nvvm/src/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use rustc_middle::ty::layout::{
1414
FnAbiError, FnAbiOf, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout,
1515
};
1616
use rustc_middle::ty::layout::{FnAbiOfHelpers, LayoutOfHelpers};
17-
use rustc_middle::ty::{Ty, TypeFoldable, TypeVisitable, TypeVisitableExt};
17+
use rustc_middle::ty::{Ty, TypeVisitable, TypeVisitableExt};
18+
use rustc_middle::ty::TypeFoldable;
1819
use rustc_middle::{bug, span_bug, ty};
1920
use rustc_middle::{
2021
mir::mono::CodegenUnit,

crates/rustc_codegen_nvvm/src/debug_info/create_scope_map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
22
use rustc_codegen_ssa::traits::*;
3+
use rustc_index::Idx;
34
use rustc_middle::ty::layout::FnAbiOf;
45

56
use crate::context::CodegenCx;

crates/rustc_codegen_nvvm/src/debug_info/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_hir::def::CtorKind;
88
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
9+
use rustc_index::Idx;
910
use rustc_index::vec::{Idx, IndexVec};
10-
use rustc_abi::FieldIdx;
1111
use rustc_middle::mir::{self, GeneratorLayout};
1212
use rustc_middle::ty::layout::{self, IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout};
1313
use rustc_middle::ty::subst::GenericArgKind;
@@ -1677,7 +1677,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
16771677
fn field_name(&self, i: usize, cx: &CodegenCx<'_, 'tcx>) -> String {
16781678
let field_name = match *self {
16791679
VariantInfo::Adt(variant) if variant.ctor_kind() != Some(CtorKind::Fn) => {
1680-
Some(variant.fields[FieldIdx::from_usize(i)].ident(cx.tcx).name)
1680+
Some(variant.fields[Idx::new(i)].ident(cx.tcx).name)
16811681
}
16821682
VariantInfo::Generator {
16831683
generator_layout,

crates/rustc_codegen_nvvm/src/intrinsic.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::llvm::{self, Value};
44
use crate::target;
55
use crate::ty::LayoutLlvmExt;
66
use crate::{builder::Builder, context::CodegenCx};
7-
use rustc_codegen_ssa::mir::place::PlaceRef;
87
use rustc_codegen_ssa::errors::InvalidMonomorphization::BasicIntegerType;
8+
use rustc_codegen_ssa::mir::place::PlaceRef;
99
use rustc_codegen_ssa::traits::DerivedTypeMethods;
1010
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods, ConstMethods, OverflowOp};
1111
use rustc_codegen_ssa::{mir::operand::OperandRef, traits::IntrinsicCallMethods};
@@ -199,6 +199,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
199199
_ if simple.is_some() => self.call(
200200
self.type_i1(),
201201
None,
202+
None,
202203
simple.unwrap(),
203204
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
204205
None,
@@ -208,6 +209,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
208209
self.call(
209210
self.type_i1(),
210211
None,
212+
None,
211213
expect,
212214
&[args[0].immediate(), self.const_bool(true)],
213215
None,
@@ -218,6 +220,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
218220
self.call(
219221
self.type_i1(),
220222
None,
223+
None,
221224
expect,
222225
&[args[0].immediate(), self.const_bool(false)],
223226
None,
@@ -227,7 +230,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
227230
let try_func = args[0].immediate();
228231
let data = args[1].immediate();
229232

230-
self.call(self.type_i1(), None, try_func, &[data], None);
233+
self.call(self.type_i1(), None, None, try_func, &[data], None);
231234
let ret_align = self.data_layout().i32_align.abi;
232235
self.store(self.const_i32(0), llresult, ret_align)
233236
}
@@ -240,6 +243,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
240243
self.call(
241244
self.type_i1(),
242245
None,
246+
None,
243247
intrinsic,
244248
&[args[0].immediate(), args[1].immediate()],
245249
None,
@@ -318,7 +322,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
318322
_ => bug!(),
319323
};
320324
self.call(
321-
self.type_i1(),
325+
self.type_i1(),None,
322326
None,
323327
expect,
324328
&[
@@ -345,9 +349,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
345349
let (width, signed) = if let Some(res) = int_type_width_signed(ty, self.cx) {
346350
res
347351
} else {
348-
tcx
349-
.sess
350-
.emit_err(BasicIntegerType { span, name, ty });
352+
tcx.sess.emit_err(BasicIntegerType { span, name, ty });
351353
return;
352354
};
353355
if name == sym::saturating_add || name == sym::saturating_sub {
@@ -371,7 +373,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
371373
let y = self.const_bool(true);
372374
let llvm_name = &format!("llvm.{}.i{}", &name_str[..4], width);
373375
let llfn = self.get_intrinsic(llvm_name);
374-
self.call(self.type_i1(), None, llfn, &[args[0].immediate(), y], None)
376+
self.call(self.type_i1(), None,None, llfn, &[args[0].immediate(), y], None)
375377
}
376378
sym::ctpop => self.call(
377379
self.type_i1(),
@@ -394,7 +396,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
394396
}
395397
}
396398
sym::bitreverse => self.call(
397-
self.type_i1(),
399+
self.type_i1(),None,
398400
None,
399401
self.get_intrinsic(&format!("llvm.bitreverse.i{}", width)),
400402
&[args[0].immediate()],
@@ -421,7 +423,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
421423
width
422424
);
423425
let llfn = self.get_intrinsic(llvm_name);
424-
self.call(self.type_i1(), None, llfn, &[lhs, rhs], None)
426+
self.call(self.type_i1(), None, None, llfn, &[lhs, rhs], None)
425427
}
426428
_ => unreachable!(),
427429
}
@@ -492,7 +494,7 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
492494
fn assume(&mut self, val: Self::Value) {
493495
trace!("Generate assume call with `{:?}`", val);
494496
let assume_intrinsic = self.get_intrinsic("llvm.assume");
495-
self.call(self.type_i1(), None, assume_intrinsic, &[val], None);
497+
self.call(self.type_i1(), None, None, assume_intrinsic, &[val], None);
496498
}
497499

498500
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {

crates/rustc_codegen_nvvm/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use rustc_codegen_ssa::{
6161
traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods},
6262
CodegenResults, CompiledModule, ModuleCodegen,
6363
};
64+
use rustc_data_structures::fx::FxIndexMap;
6465
use rustc_errors::{ErrorGuaranteed, FatalError, Handler};
6566
use rustc_hash::FxHashMap;
6667
use rustc_metadata::EncodedMetadata;
@@ -136,7 +137,7 @@ impl CodegenBackend for NvvmCodegenBackend {
136137
ongoing_codegen: Box<dyn std::any::Any>,
137138
sess: &Session,
138139
outputs: &OutputFilenames,
139-
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
140+
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
140141
debug!("Join codegen");
141142
let (codegen_results, work_products) = ongoing_codegen
142143
.downcast::<OngoingCodegen<Self>>()
@@ -162,6 +163,10 @@ impl CodegenBackend for NvvmCodegenBackend {
162163
);
163164
Ok(())
164165
}
166+
167+
fn locale_resource(&self) -> &'static str {
168+
todo!()
169+
}
165170
}
166171

167172
impl WriteBackendMethods for NvvmCodegenBackend {
@@ -256,7 +261,9 @@ impl WriteBackendMethods for NvvmCodegenBackend {
256261
}
257262
}
258263

259-
type TargetMachineError; // idk wtf im supposed to do with this but ill fix later
264+
type TargetMachineError;
265+
266+
// type TargetMachineError; // idk wtf im supposed to do with this but ill fix later
260267

261268
// fn run_lto_pass_manager(
262269
// _: &CodegenContext<Self>,

crates/rustc_codegen_nvvm/src/link.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -108,32 +108,32 @@ pub fn link<'tcx>(
108108
}
109109

110110
if outputs.outputs.should_codegen() {
111-
let out_filename: OutFileName = out_filename(
111+
let out_filename = out_filename(
112112
sess,
113113
crate_type,
114114
outputs,
115115
codegen_results.crate_info.local_crate_name,
116116
);
117117
match crate_type {
118118
CrateType::Rlib => {
119-
link_rlib(sess, codegen_results, &out_filename);
119+
link_rlib(sess, codegen_results, &out_filename.as_path());
120120
}
121121
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib => {
122122
let _ = link_exe(
123123
&codegen_results.allocator_module,
124124
sess,
125125
crate_type,
126-
&out_filename,
126+
&out_filename.as_path(),
127127
codegen_results,
128128
);
129129
}
130-
other => sess.fatal(&format!("Invalid crate type: {:?}", other)),
130+
other => sess.fatal(format!("Invalid crate type: {:?}", other)),
131131
}
132132
}
133133
}
134134
}
135135

136-
fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &OutFileName) {
136+
fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Path) {
137137
debug!("Linking rlib `{:?}`", out_filename);
138138
let mut file_list = Vec::<&Path>::new();
139139

@@ -167,7 +167,7 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Ou
167167
// the binary directly to ptx. We might want to add some way of linking in
168168
// ptx files or custom bitcode modules as "libraries" perhaps in the future.
169169
if let Some(name) = lib.name {
170-
sess.err(&format!(
170+
sess.err(format!(
171171
"Adding native libraries to rlib is not supported in CUDA: {}",
172172
name
173173
));
@@ -224,7 +224,7 @@ fn codegen_into_ptx_file(
224224
sess: &Session,
225225
objects: &[PathBuf],
226226
rlibs: &[PathBuf],
227-
out_filename: &OutFileName,
227+
out_filename: &Path,
228228
) -> io::Result<()> {
229229
debug!("Codegenning crate into PTX, allocator: {}, objects:\n{:#?}, rlibs:\n{:#?}, out_filename:\n{:#?}",
230230
allocator.is_some(),
@@ -285,21 +285,21 @@ fn codegen_into_ptx_file(
285285
Ok(bytes) => bytes,
286286
Err(err) => {
287287
// TODO(RDambrosio016): maybe include the nvvm log with this fatal error
288-
sess.fatal(&err.to_string())
288+
sess.fatal(err.to_string())
289289
}
290290
};
291291

292292
std::fs::write(out_filename, ptx_bytes)
293293
}
294294

295-
fn create_archive(sess: &Session, files: &[&Path], metadata: &[u8], out_filename: &OutFileName) {
295+
fn create_archive(sess: &Session, files: &[&Path], metadata: &[u8], out_filename: &Path) {
296296
if let Err(err) = try_create_archive(files, metadata, out_filename) {
297-
sess.fatal(&format!("Failed to create archive: {}", err));
297+
sess.fatal(format!("Failed to create archive: {}", err));
298298
}
299299
}
300300

301301
fn try_create_archive(files: &[&Path],
302-
metadata: &[u8], out_filename: &OutFileName) -> io::Result<()> {
302+
metadata: &[u8], out_filename: &Path) -> io::Result<()> {
303303
let file = File::create(out_filename)?;
304304
let mut builder = Builder::new(file);
305305
{

crates/rustc_codegen_nvvm/src/mono_item.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub use rustc_middle::mir::mono::MonoItem;
1111
use rustc_middle::mir::mono::{Linkage, Visibility};
1212
use rustc_middle::ty::layout::FnAbiOf;
1313
use rustc_middle::ty::layout::LayoutOf;
14-
use rustc_middle::ty::{self, Instance, TypeFoldable, TypeVisitable, TypeVisitableExt};
14+
use rustc_middle::ty::{self, Instance, TypeVisitable, TypeVisitableExt};
15+
use rustc_middle::ty::TypeFoldable;
1516
use tracing::trace;
1617

1718
pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {

0 commit comments

Comments
 (0)